[英]Navigation Drawer icon not showing (Sherlock actionbar)
Have the navigation Drawer working with the sherlock actionbar but i am having trouble getting the 3 line icon (like gmail) to show instead of the normal up button "<". 让导航抽屉与sherlock操作栏一起使用但我无法显示3行图标(如gmail)而不是正常的向上按钮“<”。 Here is my code ic_drawer is the 3 line icon that gmail uses 这是我的代码ic_drawer是gmail使用的3行图标
getSupportActionBar().setIcon(R.drawable.myIcon);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer,
R.drawable.ic_drawer, R.string.menu_open, R.string.menu_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
Have you tried implementing the method: 您是否尝试过实施该方法:
mDrawerToggle.syncState();
This has worked for me in the past. 这在过去对我有用。
This solution worked for me, and showed default navigation drawer icon in all version. 此解决方案适用于我,并在所有版本中显示默认导航抽屉图标。 Add SherlockNavigationDrawer
library from here https://github.com/nicolasjafelle/SherlockNavigationDrawer to your project. 从这里添加SherlockNavigationDrawer
库https://github.com/nicolasjafelle/SherlockNavigationDrawer到您的项目。 And change your code as below : 并更改您的代码如下:
SherlockActionBarDrawerToggle mDrawerToggle = new SherlockActionBarDrawerToggle(this,mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
Though I'm guessing by now you must have worked it out, just wanted to submit an answer: 虽然我现在猜你已经把它解决了,只是想提交一个答案:
Change your code to the following: 将您的代码更改为以下内容:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer,
R.drawable.ic_drawer, R.string.menu_open, R.string.menu_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setIcon(R.drawable.myIcon);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
Essentially, the ActionBar options that you are setting in code need to be set after the DrawerToggle has been completed, not before. 基本上,您在代码中设置的ActionBar选项需要在DrawerToggle完成之后设置,而不是之前。
You can look at this post first. 你可以先看看这篇文章。 There is one answer: "You can change back icon in Theme 有一个答案:“你可以改变主题中的图标
<item name="android:homeAsUpIndicator">@drawable/action_arrow</item>
But I think you want implement Navigation Drawer , so read about it. 但我认为你想要实现导航抽屉 ,所以阅读它。
What you can do is create a style like below: 您可以做的是创建如下样式:
<style name="AppTheme" parent="Your Theme name">
<item name="homeAsUpIndicator">@drawable/ic_drawer</item>
</style>
And in Android manifest apply this theme like: 在Android清单中应用此主题,如:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</application>
This will solve the issue getting the 3 line icon for sure. 这将解决获得3行图标的问题。
你有把肘节添加到抽屉吗?
mDrawerLayout.setDrawerListener(mDrawerToggle);
This happen when you run your app in Android < 3, even Google apps suffer of this too. 当你在Android <3中运行你的应用程序时,就会发生这种情况,甚至Google应用程序也会受到影响。
But there is a project than solve this: https://github.com/nicolasjafelle/SherlockNavigationDrawer 但是有一个项目而不是解决这个问题: https : //github.com/nicolasjafelle/SherlockNavigationDrawer
I put this in and it works. 我把它放进去并且它有效。
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@zudo1337 's method solved my problem. @ zudo1337的方法解决了我的问题。
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
I have added this line before calling setDrawerListener. 我在调用setDrawerListener之前添加了这一行。
mDrawerLayout.post(new Runnable() {
@Override public void run() {
mDrawerToggle.syncState();
}
});
Hope this will fix the issue in lower devices. 希望这将解决较低设备中的问题。
May be this will work... 可能这会起作用......
in onCreateOptionMenu inflate your menu layout getSupportMenuInflater().inflate(R.menu.action_bar_menu, menu); 在onCreateOptionMenu中夸大你的菜单布局getSupportMenuInflater()。inflate(R.menu.action_bar_menu,menu);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.