[英]Using Navigation Drawer with other activities
First question here, hope I'll get the help I need :) First of all I tried to check at this thread: Same Navigation Drawer in different Activities and a lot others and got nothing :\\ 这里的第一个问题,希望我能得到我需要的帮助:)首先,我尝试检查此线程: 在不同的Activity中使用相同的导航抽屉,在许多其他活动中却没有得到任何帮助:\\
Question: 题:
So I make a app that supposed to be built like this: 因此,我制作了一个应如下构建的应用程序:
Navigation Drawer - over all the activities. 导航抽屉-所有活动。
Main page that contain information 包含信息的主页
Activity 活动
I made the options on the drawer to go to another activities but: 我在抽屉上做了一些选择,可以去参加其他活动,但是:
How do I make an option that when I'm currently in an activity and I press in the drawer again on the button that send me to the same activity it will just close the drawer? 我该如何选择一个选项,当我当前处于活动中并再次按抽屉中的按钮(使我转至同一活动)时,它只会关闭抽屉? there is any option to check if I'm right now in a specific activity? 是否可以检查我是否正在参加特定活动? here is my main page with the drawer: 这是我带抽屉的主页:
public class Main_Page extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main__page); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); } @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } } @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { Intent Home=new Intent(Main_Page.this,Main_Page.class); Intent Settings = new Intent(Main_Page.this,Settings.class); int id = item.getItemId(); if (id == R.id.Main_App) startActivity(Home); else if (id== R.id.nav_Settings) startActivity(Settings); else if (id == R.id.Nav_Log_Out) { super.onBackPressed(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } }
Thank you ! 谢谢 !
It is not possible, you have two options 这是不可能的,您有两种选择
Finally both solutions has pros and cons, and it depends on you business logic and how complicated each section is 最后,两种解决方案都有其优缺点,这取决于您的业务逻辑以及每个部分的复杂程度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.