如何从Android ActionBar中删除标题文本?
我正在浏览Holo.Light主题,我似乎无法找到魔术风格来覆盖,以摆脱我的应用程序首次启动时短暂显示的标题文本。
我怎样才能做到这一点?
20个解决方案
201 votes
尝试:
getActionBar()setDisplayShowTitleEnabled(假)。
对于第7节:
getSupportActionBar()setDisplayShowTitleEnabled(假)。
Filippo Mazza answered 2019-07-28T00:34:35Z
93 votes
我认为这是正确的答案:
@style/Widget.Styled.ActionBar
@style/Widget.Styled.ActionBar
showHome|useLogo
showHome|useLogo
cesards answered 2019-07-28T00:34:59Z
63 votes
我对Android很新,所以如果我错了就纠正我,但我想如果你决定在Action Bar上使用导航标签,它们似乎没有完全左对齐,因为标题文字颜色只是透明的并且没有' 走开了。
useLogo|showHome
为我工作。
sparknoob answered 2019-07-28T00:35:25Z
41 votes
得到它了。 你必须覆盖
android:actionBarStyle
然后在您的自定义样式中,您必须覆盖
android:titleTextStyle
这是一个样本。
在我的themes.xml中:
@style/CustomActionBarStyle
在我的styles.xml中:
@style/NoTitleText
@style/NoTitleText
0sp
#00000000
我不确定为什么将textSize设置为零并没有做到这一点(它缩小了文本,但没有让它消失),但是将textColor设置为透明工作。
Christopher Perry answered 2019-07-28T00:36:22Z
20 votes
在你的清单中
android:label="">
easycheese answered 2019-07-28T00:36:47Z
12 votes
写下这个陈述
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowTitleEnabled(false);
如果扩展AppCompactActivity使用android:label=""如果扩展活动使用android:label=""否则它可能会给
null pointer exception
在AndroidManifest.xml中使用android:label=""进行活动也有效但你的应用程序不会出现在Recently used apps
Manohar Reddy answered 2019-07-28T00:37:25Z
7 votes
你有两个选择:
第一:
getActionBar().setDisplayShowTitleEnabled(false);
如果使用getActionBar()产生空指针异常,则应使用getSupportActionBar()
第二
getSupportActionBar().setTitle("your title");
要么
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();
Hamid answered 2019-07-28T00:38:12Z
6 votes
我在App清单中使用此代码
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:logo="@drawable/logo2"
android:label="@string/title_text"
android:theme="@style/Theme.Zinoostyle" >
我的徽标文件是200 * 800像素并在main activity.java中使用此代码
getActionBar().setDisplayShowTitleEnabled(false);
它会正常工作
Milaaaad answered 2019-07-28T00:38:49Z
5 votes
您可以更改应用于每个活动的样式,或者如果您只想更改特定活动的行为,可以尝试以下操作:
setDisplayOptions(int options, int mask) --- Set selected display
or
setDisplayOptions(int options) --- Set display options.
要在操作栏上显示标题,请在onCreate()中设置显示选项
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
隐藏操作栏上的标题。
getSupportActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
细节在这里。
Siqi Liu answered 2019-07-28T00:39:34Z
5 votes
我试过这个。 这会有所帮助 -
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
应该在setSupportActionBar之后调用getSupportActionBar,因此设置工具栏,否则为NullpointerException,因为没有工具栏集。希望这可以帮助
yashpandey answered 2019-07-28T00:40:06Z
3 votes
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();
希望这会有所帮助
MeshPadukka answered 2019-07-28T00:40:30Z
2 votes
使用以下内容:
requestWindowFeature(Window.FEATURE_NO_TITLE);
Vivek answered 2019-07-28T00:40:50Z
2 votes
如果您只想为一个活动而且甚至可以动态地执行此操作,您也可以使用
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);
Heiko Rupp answered 2019-07-28T00:41:15Z
2 votes
唯一真正对我有用的是添加:
android:name=".ActivityHere"
android:label=""
>
Andreas-HD answered 2019-07-28T00:41:39Z
1 votes
作为一种解决方法,只需添加此行,即可拥有自定义操作/工具栏
this.setTitle("");
在你的活动中
Mihsen answered 2019-07-28T00:42:12Z
1 votes
虽然所有这些都是可以接受的,但如果您的活动仅包含主要活动,您可以像这样编辑res\values\styles.xml:
@color/colorPrimary
@color/colorPrimaryDark
@color/colorAccent
我已更新parent并将.NoActionBar属性添加到Android工作室Create Blank Application向导的Light主题中。
eyoung100 answered 2019-07-28T00:42:44Z
1 votes
只需从AppCompatActivity扩展您的java文件并执行以下操作:
ActionBar actionBar = getSupportActionBar(); // support.v7
actionBar.setTitle(" ");
HarsH answered 2019-07-28T00:43:09Z
0 votes
在manifest.xml页面中,您可以为活动标签指定地址。 地址位于values / strings.xml中的某个位置。 然后,您可以将xml文件中的标记值更改为null。
Damoon answered 2019-07-28T00:43:36Z
0 votes
我是Android的新手,所以也许我错了......但要解决这个问题,我们只能去清单并删除活动标签
android:name=".Bcft"
android:screenOrientation="portrait"
**android:label="" >**
为我工作....
Ebin Xavier Jose answered 2019-07-28T00:44:08Z
-3 votes
ActionBar actionBar = getActionBar();
actionBar.setTitle("");
Joe Lewis answered 2019-07-28T00:44:27Z