gpt4 book ai didi

android - 抽屉导航图标 (ic_drawer) 未显示

转载 作者:IT老高 更新时间:2023-10-28 22:04:20 25 4
gpt4 key购买 nike

我正在为我的应用实现一个抽屉式导航。现在它工作得很好,除了一个小故障。当我设置抽屉导航图标 (ic_drawer) 以替换常规的“HomeAsUp”插入符号图标时,我仍然得到箭头。抽屉导航图标不显示。我已经实现了 android 开发者网站上的所有方法。但这似乎不起作用。

下面是我的代码:

DrawerLayout mDrawerLayout;
FrameLayout leftDrawer, rightDrawer, contentFrame;
ActionBarDrawerToggle mDrawerToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
initializeViews();
}

private void initializeViews() {
// TODO Auto-generated method stub
mDrawerLayout = (DrawerLayout) findViewById(R.id.mDrawerLayout);
mDrawerToggle = new ActionBarDrawerToggle(this,
mDrawerLayout, R.drawable.ic_drawer,
R.string.drawer_open_content_desc,
R.string.drawer_close_content_desc);

getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);

mDrawerLayout.setDrawerListener(mDrawerToggle);

leftDrawer = (FrameLayout) findViewById(R.id.drawerLeft_frame);
rightDrawer = (FrameLayout) findViewById(R.id.drawerRight_frame);
contentFrame = (FrameLayout) findViewById(R.id.content_frame);
}


@Override
protected void onPostCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}

最佳答案

我知道现在回答这个问题已经很晚了,但这至少会对某人有所帮助。

您可能应该添加这些代码行来显示导航图标。

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}

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

关于android - 抽屉导航图标 (ic_drawer) 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20385101/

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