简体   繁体   English

使用选项卡时,自定义操作栏标题不带图标

[英]Custom action bar title without icon when using tabs

I'm trying to set the color of my custom action bar from black to silver. 我正在尝试将自定义操作栏的颜色从黑色设置为银色。 The following images show what my app looks like at the moment. 下图显示了我的应用目前的样子。 I'm trying to get rid of the black bar on the second image. 我试图摆脱第二张图片上的黑条。 I'm using the following code: 我正在使用以下代码:

final ActionBar actionBar = getActionBar(); 最后的ActionBar actionBar = getActionBar(); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME); actionBar.setCustomView(R.layout.action_bar); actionBar.setCustomView(R.layout.action_bar);

Can anyone help me figure out what's wrong? 谁能帮助我找出问题所在?

在此处输入图片说明

在此处输入图片说明

I'm trying to get rid of the black bar on the second image 我试图摆脱第二张图片上的黑条

change android:layout_marginLeft="-20dp" to android:layout_marginLeft="0dp" android:layout_marginLeft="-20dp"更改为android:layout_marginLeft="0dp"

Update: 更新:

this is your icon that you put so remove that: 这是您放置的图标,因此请删除该图标:

    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);

use this, this will solve ur problem 用这个,可以解决你的问题

 getActionBar().setDisplayShowCustomEnabled(true);
    getActionBar().setCustomView(R.layout.demo);
    getActionBar().setDisplayShowHomeEnabled(false);

I forgot that I left this question high and dry as I was in a hurry to finish this project. 我忘了我急着完成这个项目,把这个问题留在高处。 I ended up fixing the issue by using the AccentFragmentActivity.java . 我最终通过使用AccentFragmentActivity.java解决了这个问题。 I had put in an issue here on Github. 我已经把在一个问题在这里 Github上。 Since others weren't able to replicate this I think there was just some setting off that I couldn't locate, but if anyone runs to this in the future then maybe try using AccentFragmentActivity! 由于其他人无法复制此内容,因此我认为只有一些我无法找到的偏移,但是如果将来有人遇到这种情况,则可以尝试使用AccentFragmentActivity!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM