How do you remove the title text from the Android ActionBar?
Asked Answered
C

21

109

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?

Chaker answered 5/10, 2011 at 1:38 Comment(0)
C
44

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.

Chaker answered 5/10, 2011 at 2:9 Comment(2)
Yes that helped. Any idea why android:visibility=gone has no effect? Or better yet, why does setDisplayShowTitleEnabled still show the title text while the bar is loading?Royalty
Use <item name="android:displayOptions">useLogo|showHome</item> instead of setting size to 0Tessy
T
222

Try:

 getActionBar().setDisplayShowTitleEnabled(false);

For v.7:

 getSupportActionBar().setDisplayShowTitleEnabled(false);
Tadich answered 14/7, 2012 at 18:54 Comment(5)
you will still see the title while the action bar is loading which is not what you want. the right solution is what m3n0R suggested.Possibly
it should be getSupportActionBar().setDisplayShowTitleEnabled(false); for v7 . othewise it will produce null pointer execptionHypoglossal
@numansalati Who is m3n0R? I've searched the page and found nothingMaquis
When should I cal the methods? I mean from which method (activity, fragment) should it be called?Maquis
You just need this once, in onCreate of your MainActivity.tk. This is the right solution, ignore the comments above.Crystallo
H
96

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>
Hovel answered 14/1, 2013 at 3:47 Comment(7)
What about Android 4? I am not using ActionBarSherlock so there is no resource named Widget.Sherlock.Light.ActionBar.Solid.Inverse. What parent should I use?Meridional
Holo Theme. By default there are 3 holo themes you can extend on.Hovel
This works for hiding the title on first launch. In another activity calling setTitle doesn't work. Is there a way to swap action bar styles at runtime?Nabonidus
setting the default theme on runtime :)Hovel
@domji84, You can specify the theme of each activity in the manifest file.Sufflate
I had to set the android:actionBarStyle on the style of the Activity, not the Application. So, use parent=@style/Theme.AppCompat and apply to the Activity. Just a tip to others struggling to get this working.Frequently
For Android 4, you can extend from Widget.AppCompat.Light.ActionBar.Solid.InverseLamasery
S
63

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.

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

worked for me.

Shopwindow answered 12/7, 2012 at 22:50 Comment(4)
yes,you are wrong, no tabs in question and no holo light in your answerOnfroi
While am try this, am getting this error, @android:style/Widget.Holo.ActionBar requires API level 11 (current min is 10).Salzhauer
If I want to assign this style to action bar of a specific activity and not for all the activities of my application. How can I do it? where do I put the 'android:displayOptions' line? in Menu.xml? In AndroidMenifest.xml?Calais
How is that supposed to work? Please add more details for a end-to-end solution.Crystallo
C
44

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.

Chaker answered 5/10, 2011 at 2:9 Comment(2)
Yes that helped. Any idea why android:visibility=gone has no effect? Or better yet, why does setDisplayShowTitleEnabled still show the title text while the bar is loading?Royalty
Use <item name="android:displayOptions">useLogo|showHome</item> instead of setting size to 0Tessy
P
24

In your Manifest

<activity android:name=".ActivityHere"
     android:label="">
Pruitt answered 30/3, 2012 at 3:19 Comment(3)
This does work, but will stop your app appearing in the 'Recently used apps' chooserWavelength
this make the app don't have name on phone applications / main screenDisturb
Hi @RupertBates, @Nimitack, it seems works if you assign your app name in the application tab, i.e., <application android:label="your_app_name">...Cinerarium
L
14

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

Lifeless answered 20/6, 2016 at 10:1 Comment(0)
E
9

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();
Emendate answered 29/9, 2016 at 14:19 Comment(0)
E
6

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()

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

To hide title on actionbar.

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

Details here.

Earthling answered 14/8, 2014 at 22:32 Comment(0)
R
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

getActionBar().setDisplayShowTitleEnabled(false);

it will work Corectly

Roadster answered 25/5, 2015 at 14:36 Comment(0)
F
6

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

Freestyle answered 5/9, 2017 at 11:28 Comment(0)
G
3

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

<activity 
    android:name=".ActivityHere"
    android:label=""
>
Good answered 4/4, 2014 at 23:46 Comment(2)
well was the "wrong" answer,however it help me with a similar case :)Functional
Don't do this as it will crash your application when minimizedSollie
C
3

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

this.setTitle("");

in your Activity

Clarkia answered 20/1, 2016 at 7:45 Comment(0)
F
3
getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().hide();

hope this will help

Featured answered 9/7, 2016 at 17:28 Comment(0)
G
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);
Giulio answered 30/3, 2013 at 22:1 Comment(0)
T
1

Use the following:

requestWindowFeature(Window.FEATURE_NO_TITLE);
Tendentious answered 5/10, 2011 at 2:6 Comment(3)
You can't do that if you're using the ActionBar. If you try to do this the app will immediately crash when it opens.Chaker
@ChristopherPerry not true. you can use this to remove the action bar in code, provided you do it before calling setContentView.Possibly
though, this is removing the whole actionbar instead of just its title!Bursarial
A
1

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.

Aphotic answered 4/6, 2016 at 4:42 Comment(1)
That will disable entire action bar not only title. And if you want to create blank action bar you will have to do it for every single view.Viera
D
1

Simply extends your java file from AppCompatActivity and do this:

ActionBar actionBar = getSupportActionBar(); // support.v7
actionBar.setTitle(" ");
Debose answered 5/2, 2018 at 10:5 Comment(0)
I
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 version="1.0" encoding="utf-8"?>
<resources>
    <string name="title_main_activity"></string>
</resources>
Ioyal answered 23/3, 2015 at 9:42 Comment(0)
F
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

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

        **android:label="" >**

Worked for me....

Farris answered 9/6, 2015 at 4:57 Comment(0)
M
0

I remove the default appbar and run a custom toolbar instead using Theme.AppCompat.Light.NoActionBar then add a textview or something that extend to full toolbar width using attribute layout_width=match_parent and it pushes the title out of the toolbar. If you want to do this, you must study how to make a toolbar.

Minhminho answered 4/8, 2022 at 23:18 Comment(0)
S
-3
ActionBar actionBar = getActionBar();
actionBar.setTitle("");
Swearword answered 8/2, 2013 at 11:17 Comment(1)
@Matteo Although it may work, it's certainly sketchy and not the right way to do it. In fact, it doesn't actually remove the title text, it just sets it to "", so that you cannot see it.Sistrunk

© 2022 - 2024 — McMap. All rights reserved.