Remove Icon but have HomeAsUp in ActionBar

2019-02-01 19:07发布

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

like this:

enter image description here

I tried this:

actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle("My Profile");
actionBar.setDisplayUseLogoEnabled(false);

But it gives the application icon between the title and back arrow

Thank You

8条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-01 19:07

Try to set this thing

actionBar.setLogo(null);
查看更多
迷人小祖宗
3楼-- · 2019-02-01 19:08

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

查看更多
Explosion°爆炸
4楼-- · 2019-02-01 19:10

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);
查看更多
手持菜刀,她持情操
5楼-- · 2019-02-01 19:10
getActionBar().setHomeButtonEnabled(true);//used to navigate to home
 getActionBar().setDisplayHomeAsUpEnabled(false);//used to hide the left caret symbol
查看更多
来,给爷笑一个
6楼-- · 2019-02-01 19:17

To hide action bar icon following methods works for me

method-1:getActionBar().setIcon(android.R.color.transparent);
method-2:getActionBar().setIcon(null);
查看更多
地球回转人心会变
7楼-- · 2019-02-01 19:23

If you do not want the icon in particular activity.

getActionBar().setIcon(
   new ColorDrawable(getResources().getColor(android.R.color.transparent)));
查看更多
登录 后发表回答