gpt4 book ai didi

android - 如何使用 AppCompat 库在 ActionBar 中显示 NavigationDrawer 图标

转载 作者:行者123 更新时间:2023-11-30 02:46:41 26 4
gpt4 key购买 nike

我对 NavigationDrawer 图标有疑问,我希望它在 ActionBar 中可见。需要向用户展示,他可以通过从屏幕左边缘滑动来打开我应用程序中的抽屉。 android

我以前使用这段代码没有任何问题,但在这个应用程序中它不能正常工作,我不知道问题出在哪里。请帮助我。

这是我的代码:

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);

ArrayList<Integer> smIcon_adrs = new ArrayList<Integer>();
smIcon_adrs.add(R.drawable.sm_font);
smIcon_adrs.add(R.drawable.sm_size);
smIcon_adrs.add(R.drawable.sm_count);
smIcon_adrs.add(R.drawable.sm_about);
ArrayAdapter<Integer> sm_adapter = new smIcoAdapter(getBaseContext(),
smIcon_adrs);

mDrawerList.setAdapter(sm_adapter);

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.hello_world, R.string.app_name) {

/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {

getSupportActionBar().setTitle("دعا عهد");
supportInvalidateOptionsMenu();
super.onDrawerClosed(view);
}

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle("امکانات");
supportInvalidateOptionsMenu();
super.onDrawerOpened(drawerView);
// onPrepareOptionsMenu()
}
};

mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerLayout.setDrawerListener(mDrawerToggle);

这里:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);

return super.onCreateOptionsMenu(menu);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_play:
if (mp.isPlaying()) {
item.setIcon(R.drawable.actn_play);
mp.pause();
} else {
updateProgressBar();
mp.start();
item.setIcon(R.drawable.actn_stop);
}
break;

}
if (mDrawerToggle.onOptionsItemSelected(item)) {

return true;
}
return super.onOptionsItemSelected(item);
}
public boolean onPrepareOptionsMenu(Menu menu) {
mDrawerLayout.isDrawerOpen(mDrawerList);
// menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}

最佳答案

这里有人有类似的问题,你可以测试那里发布的解决方案:https://stackoverflow.com/a/23332975/1738838 .

据此,您缺少此方法:

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}

关于android - 如何使用 AppCompat 库在 ActionBar 中显示 NavigationDrawer 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24884214/

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