Remove Icon but have HomeAsUp in ActionBar

前端 未结 8 1324
遥遥无期
遥遥无期 2020-12-25 12:16

I what my actionbar to have a title and homeAsUp but not the logo or icon.

like this:

相关标签:
8条回答
  • 2020-12-25 12:22

    Open your styles.xml file and add below codes in your Actionbar style

    <item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
    <item name="displayOptions">showHome|homeAsUp|showTitle</item>
    <item name="android:icon">@android:color/transparent</item> <--this do the magic!
    

    p/s: I'm using Actionbar Sherlock and this works just fine

    0 讨论(0)
  • 2020-12-25 12:23
    getActionBar().setIcon(
    new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    

    it works for me.

    0 讨论(0)
  • 2020-12-25 12:32

    To hide the icon as well try using setIcon(null)

    actionBar = getSupportActionBar();
    actionBar.setTitle("My Profile");
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setIcon(null);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    
    0 讨论(0)
  • 2020-12-25 12:41
    actionBar = getSupportActionBar();    
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle("My Profile");
    actionBar.setDisplayUseLogoEnabled(false);
    
    0 讨论(0)
  • 2020-12-25 12:43

    If you do not want the icon in particular activity.

    getActionBar().setIcon(
       new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    
    0 讨论(0)
  • 2020-12-25 12:43

    To hide action bar icon following methods works for me

    method-1:getActionBar().setIcon(android.R.color.transparent);
    method-2:getActionBar().setIcon(null);
    
    0 讨论(0)
提交回复
热议问题