我有“活动 A”和“活动 B”。在“活动 A”中,底部导航栏工作得非常好。现在我需要与“活动 A”相同的底部导航栏才能在“活动 B”中工作。我已经创建了“Activity B”中底部导航栏的布局相同,并尝试导入“Activity 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:
//Here how can i use method of "Activity A"
break;
case R.id.nav_mode_favs:
//Here how can i use method of "Activity A"
break;
case R.id.nav_mode_saved:
//Here how can i use method of "Activity A"
break;
case R.id.nav_mode_hidden:
//Here how can i use method of "Activity A"
break;
case R.id.nav_more:
//Here how can i use method of "Activity A"
break;
}
return true;
}