Navigation Drawer Icon (ic_drawer) not showing

痞子三分冷 提交于 2019-11-29 01:06:24

I know it is quite late to answer this but this would help someone atleast.

You should probably add these lines of code to show that navigation icon.

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

Simply put this code in your styles.xml file:

<item name="homeAsUpIndicator">@drawable/ic_drawer</item>
<item name="android:homeAsUpIndicator">@drawable/ic_drawer</item>

I had this same problem and this worked for me.

EDIT

Programmatically you can set: getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer);

You have to put this code:

getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer);

or

getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer);

I hope that this code help you.

I solved the same issue by having a <meta-data> specified for my activity but the android:value points to the same Activity.

Hence, if say Activity name is MainActivity then add the below tag to your activity in the manifest file.

<meta-data
     android:name="android.support.PARENT_ACTIVITY"
     android:value="com.example.MainActivity" />

Hope this helps. :)

Check in the AndroidManifest.xml, for the that specific activity NOT to have the meta-data "android.support.PARENT_ACTIVITY" set. Try removing the <meta-data> if it's set like this:

<activity> 
...
 <meta-data
    android:name="android.support.PARENT_ACTIVITY"
    android:value="com.company.project.ParentActivity"/>
</activity>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!