简体   繁体   English

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

[英]Auto open drawable after start app android

I want Auto open drawable after start app android我想在启动应用程序 android 后自动打开可绘制对象

used library https://github.com/mikepenz/MaterialDrawer使用库https://github.com/mikepenz/MaterialDrawer

this code from Main Activity If it possible if possible And the second question is, can I open the menu on all activities after the swipe to the right?此代码来自 Main Activity 如果可能的话第二个问题是,我可以在向右滑动后打开所有活动的菜单吗? Only the back button now works现在只有后退按钮有效

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;
        }
    }
});

I suggest to refactor your application to single activity structure.我建议将您的应用程序重构为单一活动结构。 This will help to solve both of your problems.这将有助于解决您的两个问题。

  • You may just open the drawer in activity onCreate method.您可以在活动onCreate方法中打开抽屉。 It is called when activity created, with single activity - when app started.它在创建活动时调用,具有单个活动 - 当应用程序启动时。
  • Save that drawer was opened to instance state if you need more accuracy here and don't want the drawer to be opened on activity recreation events (states when system decides to destroy your activity to release memory)如果您在此处需要更高的准确性并且不希望在活动娱乐事件中打开抽屉(系统决定销毁您的活动以释放内存时的状态),请保存该抽屉已打开到实例 state
  • use fragments for showing app screens使用片段显示应用程序屏幕
  • open drawer in this single activity and manage toolbar from activity so it could be opened on every screen在此单个活动中打开抽屉并从活动管理工具栏,以便可以在每个屏幕上打开它

Single activity is the way google recommends to structure apps.单一活动是谷歌推荐的构建应用程序的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM