如何从Android ActionBar删除标题文本?

时间:2022-05-10 02:47:41

I'm looking through the Holo.Light theme, and I can't seem to find the magic style to override to get rid of the title text that briefly shows up when my app first launches.

我在看全息图。轻主题,我似乎找不到可以重写的神奇风格来删除标题文本,当我的应用程序首次启动时,标题文本会短暂地出现。

How can I do that?

我怎么做呢?

20 个解决方案

#1


183  

Try:

试一试:

getActionBar().setDisplayShowTitleEnabled(false);

getActionBar().setDisplayShowTitleEnabled(假);

For v.7:

7节:

getSupportActionBar().setDisplayShowTitleEnabled(false);

getSupportActionBar().setDisplayShowTitleEnabled(假);

#2


93  

I think this is the right answer:

我认为这是正确的答案:

<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="android:displayOptions">showHome|useLogo</item>
    <item name="displayOptions">showHome|useLogo</item>
</style>

#3


62  

I'm very new to Android so correct me if I'm wrong, but I think if you decide to use navigation tabs on the Action Bar, they seemed to not be completely left aligned because the title text color is only transparent and hasn't gone away.

我是Android的新手,所以如果我错了,请纠正我,但是我认为如果你决定在操作条上使用导航标签,它们似乎不是完全左对齐的,因为标题文本颜色是透明的,并且没有消失。

<style name="CustomActionBarStyle" parent="@android:style/Widget.Holo.ActionBar">
     <item name="android:displayOptions">useLogo|showHome</item>
</style>

worked for me.

为我工作。

#4


40  

Got it. You have to override

明白了。你必须重写

android:actionBarStyle

and then in your custom style you have to override

然后在定制样式中,你必须重写。

android:titleTextStyle

Here's a sample.

这里有一个样品。

In my themes.xml:

在我themes.xml:

<style name="CustomActionBar" parent="android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
</style>

And in my styles.xml:

在我styles.xml:

<style name="CustomActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
        <item name="android:titleTextStyle">@style/NoTitleText</item>
        <item name="android:subtitleTextStyle">@style/NoTitleText</item>
</style>

<style name="NoTitleText">
        <item name="android:textSize">0sp</item>
        <item name="android:textColor">#00000000</item>
</style>

I'm not sure why setting the textSize to zero didn't do the trick (it shrunk the text, but didn't make it go away), but setting the textColor to transparent works.

我不知道为什么将textSize设置为0并没有起到什么作用(它缩小了文本,但没有使其消失),而是将textColor设置为透明的。

#5


20  

In your Manifest

在你的清单

<activity android:name=".ActivityHere"
     android:label="">

#6


11  

Write this statement under

写这个声明下

setContentView(R.layout.activity_main);

getSupportActionBar().setDisplayShowTitleEnabled(false);

if extending AppCompactActivity use getSupportActionbar() if extending Activity use getActionBar() else it may give

如果扩展AppCompactActivity使用getSupportActionbar(),如果扩展活动使用getActionBar(),那么它可能会给出。

null pointer exception

using android:label="" in AndroidManifest.xml for activity also works but your app won't appear in Recently used apps

使用android:label = " "在AndroidManifest。xml for activity也可以,但是你的应用不会出现在最近使用的应用中

#7


7  

you have two choice:

first:

你有两个选择:第一:

getActionBar().setDisplayShowTitleEnabled(false);

If usign getActionBar() produced null pointer exception, you should use getSupportActionBar()

Second

如果usign getActionBar()产生了空指针异常,则应该使用getSupportActionBar()

getSupportActionBar().setTitle("your title");

or

getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();

#8


6  

i use this code in App manifest

我在应用程序清单中使用这个代码

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:logo="@drawable/logo2"
        android:label="@string/title_text"
        android:theme="@style/Theme.Zinoostyle" >

my logo file is 200*800 pixel and use this code in main activity.java

我的logo文件是200*800像素,在main activity.java中使用这个代码

getActionBar().setDisplayShowTitleEnabled(false);

it will work Corectly

它将工作Corectly

#9


5  

You can change the style applied to each activity, or if you only want to change the behavior for a specific activity, you can try this:

您可以更改应用于每个活动的样式,或者如果您只想更改特定活动的行为,您可以尝试以下方法:

setDisplayOptions(int options, int mask) --- Set selected display 
  or
setDisplayOptions(int options) --- Set display options.

To display title on actionbar, set display options in onCreate()

要在actionbar上显示标题,请在onCreate()中设置显示选项

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);

To hide title on actionbar.

在动作条上隐藏标题。

getSupportActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

Details here.

详情请点击这里。

#10


3  

getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().hide();

hope this will help

希望这将帮助

#11


3  

I tried this. This will help -

我试着这一点。这将帮助- - - - - -

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

getSupportActionBar should be called after setSupportActionBar, thus setting the toolbar, otherwise, NullpointerException because there is no toolbar set. Hope this helps

getSupportActionBar应该在setSupportActionBar之后调用,这样就可以设置工具栏,否则会因为没有工具栏设置而导致NullpointerException

#12


2  

Use the following:

使用以下:

requestWindowFeature(Window.FEATURE_NO_TITLE);

#13


2  

If you only want to do it for one activity and perhaps even dynamically, you can also use

如果您只想对一个活动执行此操作,甚至可能是动态地执行,您也可以使用它

ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);

#14


2  

The only thing that really worked for me was to add:

对我来说唯一起作用的是:

<activity 
    android:name=".ActivityHere"
    android:label=""
>

#15


1  

as a workaround just add this line incase you have custom action/toolbars

作为一个解决方案,只要添加这一行,以防您有自定义操作/工具栏

this.setTitle("");

in your Activity

在你的活动

#16


1  

While all of these are acceptable, if your activity only contains a main activity, you can edit res\values\styles.xml like so:

所有这些都是可以接受的,如果您的活动只包含一个主活动,您可以编辑res\值\样式。xml一样:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

I've updated parent and added the .NoActionBar property to the Light theme from Android Studios Create Blank Application Wizard.

我已经更新了父类并将. noactionbar属性添加到Android studio的Light主题Create Blank Application Wizard中。

#17


1  

Simply extends your java file from AppCompatActivity and do this:

只需从AppCompatActivity扩展您的java文件,然后这样做:

ActionBar actionBar = getSupportActionBar(); // support.v7
actionBar.setTitle(" ");

#18


0  

In your manifest.xml page you can give address to your activity label. the address is somewhere in your values/strings.xml . then you can change the value of the tag in xml file to null.

在你的清单。您可以向活动标签提供地址。地址在你的值/字符串的某个地方。xml。然后可以将xml文件中的标记值更改为null。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="title_main_activity"></string>
</resources>

#19


0  

I am new to Android so maybe I am wrong...but to solve this problem cant we just go to the manifest and remove the activity label

我是Android新手,所以可能我错了……但是要解决这个问题,我们不能只去清单和删除活动标签

<activity
        android:name=".Bcft"
        android:screenOrientation="portrait"

        **android:label="" >**

Worked for me....

为我工作....

#20


-3  

ActionBar actionBar = getActionBar();
actionBar.setTitle("");

#1


183  

Try:

试一试:

getActionBar().setDisplayShowTitleEnabled(false);

getActionBar().setDisplayShowTitleEnabled(假);

For v.7:

7节:

getSupportActionBar().setDisplayShowTitleEnabled(false);

getSupportActionBar().setDisplayShowTitleEnabled(假);

#2


93  

I think this is the right answer:

我认为这是正确的答案:

<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="android:displayOptions">showHome|useLogo</item>
    <item name="displayOptions">showHome|useLogo</item>
</style>

#3


62  

I'm very new to Android so correct me if I'm wrong, but I think if you decide to use navigation tabs on the Action Bar, they seemed to not be completely left aligned because the title text color is only transparent and hasn't gone away.

我是Android的新手,所以如果我错了,请纠正我,但是我认为如果你决定在操作条上使用导航标签,它们似乎不是完全左对齐的,因为标题文本颜色是透明的,并且没有消失。

<style name="CustomActionBarStyle" parent="@android:style/Widget.Holo.ActionBar">
     <item name="android:displayOptions">useLogo|showHome</item>
</style>

worked for me.

为我工作。

#4


40  

Got it. You have to override

明白了。你必须重写

android:actionBarStyle

and then in your custom style you have to override

然后在定制样式中,你必须重写。

android:titleTextStyle

Here's a sample.

这里有一个样品。

In my themes.xml:

在我themes.xml:

<style name="CustomActionBar" parent="android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
</style>

And in my styles.xml:

在我styles.xml:

<style name="CustomActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
        <item name="android:titleTextStyle">@style/NoTitleText</item>
        <item name="android:subtitleTextStyle">@style/NoTitleText</item>
</style>

<style name="NoTitleText">
        <item name="android:textSize">0sp</item>
        <item name="android:textColor">#00000000</item>
</style>

I'm not sure why setting the textSize to zero didn't do the trick (it shrunk the text, but didn't make it go away), but setting the textColor to transparent works.

我不知道为什么将textSize设置为0并没有起到什么作用(它缩小了文本,但没有使其消失),而是将textColor设置为透明的。

#5


20  

In your Manifest

在你的清单

<activity android:name=".ActivityHere"
     android:label="">

#6


11  

Write this statement under

写这个声明下

setContentView(R.layout.activity_main);

getSupportActionBar().setDisplayShowTitleEnabled(false);

if extending AppCompactActivity use getSupportActionbar() if extending Activity use getActionBar() else it may give

如果扩展AppCompactActivity使用getSupportActionbar(),如果扩展活动使用getActionBar(),那么它可能会给出。

null pointer exception

using android:label="" in AndroidManifest.xml for activity also works but your app won't appear in Recently used apps

使用android:label = " "在AndroidManifest。xml for activity也可以,但是你的应用不会出现在最近使用的应用中

#7


7  

you have two choice:

first:

你有两个选择:第一:

getActionBar().setDisplayShowTitleEnabled(false);

If usign getActionBar() produced null pointer exception, you should use getSupportActionBar()

Second

如果usign getActionBar()产生了空指针异常,则应该使用getSupportActionBar()

getSupportActionBar().setTitle("your title");

or

getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();

#8


6  

i use this code in App manifest

我在应用程序清单中使用这个代码

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:logo="@drawable/logo2"
        android:label="@string/title_text"
        android:theme="@style/Theme.Zinoostyle" >

my logo file is 200*800 pixel and use this code in main activity.java

我的logo文件是200*800像素,在main activity.java中使用这个代码

getActionBar().setDisplayShowTitleEnabled(false);

it will work Corectly

它将工作Corectly

#9


5  

You can change the style applied to each activity, or if you only want to change the behavior for a specific activity, you can try this:

您可以更改应用于每个活动的样式,或者如果您只想更改特定活动的行为,您可以尝试以下方法:

setDisplayOptions(int options, int mask) --- Set selected display 
  or
setDisplayOptions(int options) --- Set display options.

To display title on actionbar, set display options in onCreate()

要在actionbar上显示标题,请在onCreate()中设置显示选项

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);

To hide title on actionbar.

在动作条上隐藏标题。

getSupportActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

Details here.

详情请点击这里。

#10


3  

getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().hide();

hope this will help

希望这将帮助

#11


3  

I tried this. This will help -

我试着这一点。这将帮助- - - - - -

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

getSupportActionBar should be called after setSupportActionBar, thus setting the toolbar, otherwise, NullpointerException because there is no toolbar set. Hope this helps

getSupportActionBar应该在setSupportActionBar之后调用,这样就可以设置工具栏,否则会因为没有工具栏设置而导致NullpointerException

#12


2  

Use the following:

使用以下:

requestWindowFeature(Window.FEATURE_NO_TITLE);

#13


2  

If you only want to do it for one activity and perhaps even dynamically, you can also use

如果您只想对一个活动执行此操作,甚至可能是动态地执行,您也可以使用它

ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);

#14


2  

The only thing that really worked for me was to add:

对我来说唯一起作用的是:

<activity 
    android:name=".ActivityHere"
    android:label=""
>

#15


1  

as a workaround just add this line incase you have custom action/toolbars

作为一个解决方案,只要添加这一行,以防您有自定义操作/工具栏

this.setTitle("");

in your Activity

在你的活动

#16


1  

While all of these are acceptable, if your activity only contains a main activity, you can edit res\values\styles.xml like so:

所有这些都是可以接受的,如果您的活动只包含一个主活动,您可以编辑res\值\样式。xml一样:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

I've updated parent and added the .NoActionBar property to the Light theme from Android Studios Create Blank Application Wizard.

我已经更新了父类并将. noactionbar属性添加到Android studio的Light主题Create Blank Application Wizard中。

#17


1  

Simply extends your java file from AppCompatActivity and do this:

只需从AppCompatActivity扩展您的java文件,然后这样做:

ActionBar actionBar = getSupportActionBar(); // support.v7
actionBar.setTitle(" ");

#18


0  

In your manifest.xml page you can give address to your activity label. the address is somewhere in your values/strings.xml . then you can change the value of the tag in xml file to null.

在你的清单。您可以向活动标签提供地址。地址在你的值/字符串的某个地方。xml。然后可以将xml文件中的标记值更改为null。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="title_main_activity"></string>
</resources>

#19


0  

I am new to Android so maybe I am wrong...but to solve this problem cant we just go to the manifest and remove the activity label

我是Android新手,所以可能我错了……但是要解决这个问题,我们不能只去清单和删除活动标签

<activity
        android:name=".Bcft"
        android:screenOrientation="portrait"

        **android:label="" >**

Worked for me....

为我工作....

#20


-3  

ActionBar actionBar = getActionBar();
actionBar.setTitle("");