我有“活动A”和“活动B”。在“活动A”中,底部导航栏工作正常。现在,我需要与“活动A”相同的底部导航栏才能在“活动B”中工作。在“活动B”中创建了与底部导航栏相同的布局,并尝试导入“活动A”的功能,但该应用程序崩溃了几次。感谢您的帮助。
活动A:
switch (item.getItemId()) {
case R.id.action_picture_from_gallery: {
if (PermissionChecker.doIfPermissionGranted(this))
{
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
ActivityUtils.get(this).animateToActivity(i, false, REQUEST_LOAD_GALLERY_IMAGE);
}
return true;
}
case R.id.action_picture_from_camera: {
showCameraDialog();
//intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
//startActivityForResult(intent, 9);
//Toast.makeText(app, "Image From Camera", Toast.LENGTH_SHORT).show();
return true;
}
case R.id.nav_mode_create: {
Intent i = new Intent(MainActivity.this, ItemsActivity.class);
startActivity(i);
//selectedfragment=new HomeFragment();
break;
}
case R.id.nav_mode_favs: {
_currentMainMode = 1;
imageList = new ArrayList<>();
_emptylistText.setText(R.string.no_favourites_description__appspecific);
for (String fav : app.settings.getFavoriteMemeTemplates()) {
MemeData.Image img = MemeData.findImage(new File(fav));
if (img != null) {
imageList.add(img);
}
}
_toolbar.setTitle(R.string.favs);
break;
}
case R.id.nav_mode_saved: {
_currentMainMode = 2;
_emptylistText.setText(R.string.no_memes_saved_description__appspecific);
if (PermissionChecker.hasExtStoragePerm(this)) {
File folder = AssetUpdater.getMemesDir(AppSettings.get());
folder.mkdirs();
imageList = MemeData.getCreatedMemes();
}
_toolbar.setTitle(R.string.saved);
break;
}
case R.id.nav_mode_hidden: {
_currentMainMode = 3;
imageList = new ArrayList<>();
for (String hidden : app.settings.getHiddenMemesTemplate()) {
MemeData.Image image = MemeData.findImage(new File(hidden));
if (image != null) {
imageList.add(image);
}
}
_toolbar.setTitle(R.string.hidden);
break;
}
case R.id.nav_more: {
_currentMainMode = 4;
_toolbar.setTitle(R.string.more);
break;
}
}
活动B:
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem)
{
List<MemeData.Image> imageList = null;
switch(menuItem.getItemId())
{
case R.id.nav_mode_create:
//Intent i=new
Intent(getApplicationContext(),ItemsActivity.class);
//startActivity(i);
break;
case R.id.nav_mode_favs:
// _toolbar.setTitle(R.string.favs);
//Toast.makeText(ItemsActivity.this, "My memes star",
Toast.LENGTH_SHORT).show();
break;
case R.id.nav_mode_saved:
break;
//Intent k=new
Intent(getApplicationContext(),CallsToAttend.class);
//startActivity(k);
case R.id.nav_mode_hidden:
//Intent l=new
Intent(getApplicationContext(),CallsToAttend.class);
//startActivity(l);
break;
case R.id.nav_more:
// Intent m=new
Intent(getApplicationContext(),ViewProfile.class);
//startActivity(m);
//_currentMainMode = 4;
//_toolbar.setTitle(R.string.more);
break;
}
return true;
}
如果您使用kotlin,则相同的导入可能会使应用程序崩溃。