ActionBarDrawerToggle is not setting Drawer Indicator

前端 未结 4 1475
走了就别回头了
走了就别回头了 2021-02-04 06:09

I am trying to add the navigation drawer in my app.. Everything is working fine But now I still got the arrow icon although I replaced it with the ic_drawer from Android? Here\'

相关标签:
4条回答
  • 2021-02-04 06:46

    Just add the following line inside showGlobalContextActionBar() method (NavigationDrawerFragment.java class)

    actionBar.setHomeAsUpIndicator(R.drawable.ic_action_menu);
    

    Code snippet:

    private void showGlobalContextActionBar() {
            ActionBar actionBar = getActionBar();
            actionBar.setDisplayShowTitleEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.ic_action_menu);
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
            actionBar.setTitle(R.string.app_name);
        }
    
    0 讨论(0)
  • 2021-02-04 06:51

    try this code

       @Override
        protected void onPostCreate(Bundle savedInstanceState) {
            super.onPostCreate(savedInstanceState);
            // Sync the toggle state after onRestoreInstanceState has occurred.
            actbardrawertoggle.syncState();
        }
    
    0 讨论(0)
  • 2021-02-04 07:06

    You'll have to use

    getActionBar().setDisplayShowHomeEnabled(true);
    

    instead of

    getActionBar().setDisplayShowHomeEnabled(false);
    

    Cheers,

    Felix

    EDIT: Here's how to hide the Icon via XML:

    add this to your styles.xml: (Replace android:Widget.Holo.Light.ActionBar.Solid with android:Widget.Holo.ActionBar.Solid if you are using the dark action bar)

    <style name="ActionBarStyle" parent="android:Widget.Holo.Light.ActionBar.Solid">
        <item name="android:icon">@android:color/transparent</item>
    </style>
    

    and then add this to your Theme you have defined in AndroidManifest.xml (Standard is the AppBaseTheme in /res/values-v11/styles.xml - AppBaseTheme:

    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    

    Hope this helps!

    0 讨论(0)
  • 2021-02-04 07:10

    This worked for me when I wanted to get the menu icon back from the back arrow

    private void updateNavigationIcon() {
        if (getSupportFragmentManager().getBackStackEntryCount() == 0
                && getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(false);
            toggle.syncState();
        }
    }
    
    0 讨论(0)
提交回复
热议问题