How do you remove the title text from the Android

2019-01-10 02:55发布

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条回答
淡お忘
2楼-- · 2019-01-10 03:45

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:

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

And in my 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.

查看更多
【Aperson】
3楼-- · 2019-01-10 03:47

you have two choice:

first:

getActionBar().setDisplayShowTitleEnabled(false);

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

Second

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

or

getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();
查看更多
爷、活的狠高调
4楼-- · 2019-01-10 03:49

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

null pointer exception

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

查看更多
一纸荒年 Trace。
5楼-- · 2019-01-10 03:49

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

this.setTitle("");

in your Activity

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-10 03:49

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 version="1.0" encoding="utf-8"?>
<resources>
    <string name="title_main_activity"></string>
</resources>
查看更多
Luminary・发光体
7楼-- · 2019-01-10 03:50

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

<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.

查看更多
登录 后发表回答