gpt4 book ai didi

java - 启动应用程序后自动打开drawable android

转载 作者:行者123 更新时间:2023-12-01 17:19:50 26 4
gpt4 key购买 nike

我想在启动应用程序android后自动打开drawable

使用的库https://github.com/mikepenz/MaterialDrawer

此代码来自主 Activity 如果可以的话如果可能的话第二个问题是,向右滑动后我可以打开所有 Activity 的菜单吗?现在只有后退按钮可以使用

drawer = new DrawerBuilder()
.withActivity(this)
.withToolbar(mToolbar)
.withSelectedItem(1)
.withAccountHeader(headerResult)
.addDrawerItems(
new PrimaryDrawerItem().withIdentifier(1).withName(R.string.Home).withIcon(FontAwesome.Icon.faw_home),
new PrimaryDrawerItem().withIdentifier(2).withName(R.string.News).withIcon(FontAwesome.Icon.faw_newspaper),
new PrimaryDrawerItem().withIdentifier(3).withName("About").withIcon(FontAwesome.Icon.faw_question_circle),
new PrimaryDrawerItem().withIdentifier(4).withName("Open Source").withIcon(FontAwesome.Icon.faw_github_square),
new PrimaryDrawerItem().withIdentifier(5).withName("Rate on Google Play").withIcon(FontAwesome.Icon.faw_thumbs_up)
)
.withTranslucentStatusBar(false)
.build();
drawer.setOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
switch (position) {
case 1:
drawer.closeDrawer();
return true;
case 2:
drawer.closeDrawer();
drawer.setSelection(1);
startActivity(new Intent(context, NewsListActivity.class));
return true;
case 3:
drawer.closeDrawer();
drawer.setSelection(1);
startActivity(new Intent(context, AboutTheDevActivity.class));
return true;
case 4:
drawer.closeDrawer();
drawer.setSelection(1);
libsBuilder.start(context);
default:
return true;
}
}
});

最佳答案

我建议将您的应用程序重构为单一 Activity 结构。这将有助于解决您的两个问题。

  • 您可以在 Activity onCreate 方法中打开抽屉。当创建 Activity 时调用它,只有一个 Activity - 当应用程序启动时。
  • 如果您需要更准确,并且不希望抽屉在 Activity 重新创建事件(系统决定销毁您的 Activity 以释放内存时的状态)上打开,请将抽屉已打开保存到实例状态
  • 使用 fragment 显示应用屏幕
  • 在此单个 Activity 中打开抽屉并从 Activity 管理工具栏,以便可以在每个屏幕上打开它

单 Activity 就是出路google recommends构建应用程序。

关于java - 启动应用程序后自动打开drawable android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61318434/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com