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?

slhck
  • 36,575
  • 28
  • 148
  • 201
Christopher Perry
  • 38,891
  • 43
  • 145
  • 187

21 Answers21

222

Try:

 getActionBar().setDisplayShowTitleEnabled(false);

For v.7:

 getSupportActionBar().setDisplayShowTitleEnabled(false);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Filippo Mazza
  • 4,339
  • 4
  • 22
  • 25
  • 23
    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. – numan salati Feb 21 '13 at 01:03
  • 12
    it should be getSupportActionBar().setDisplayShowTitleEnabled(false); for v7 . othewise it will produce null pointer execption – Amir Oct 06 '15 at 14:57
  • 11
    @numansalati Who is m3n0R? I've searched the page and found nothing – ka3ak Oct 13 '18 at 10:52
  • 1
    When should I cal the methods? I mean from which method (activity, fragment) should it be called? – ka3ak Oct 13 '18 at 10:53
  • 1
    You just need this once, in `onCreate` of your `MainActivity.tk`. This is the right solution, ignore the comments above. – Houman Oct 06 '20 at 15:06
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>
cesards
  • 15,882
  • 11
  • 70
  • 65
  • 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? – Alex Semeniuk Mar 04 '13 at 07:31
  • Holo Theme. By default there are 3 holo themes you can extend on. – cesards Mar 04 '13 at 09:47
  • 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? – speedynomads Oct 23 '13 at 13:57
  • setting the default theme on runtime :) – cesards Oct 23 '13 at 15:21
  • @domji84, You can specify the theme of each activity in the manifest file. – ashishduh Jan 15 '14 at 17:42
  • 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. – Nilzor Aug 01 '14 at 09:20
  • For Android 4, you can extend from `Widget.AppCompat.Light.ActionBar.Solid.Inverse` – jmm Mar 02 '15 at 19:02
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.

sparknoob
  • 1,266
  • 14
  • 15
  • yes,you are wrong, no tabs in question and no holo light in your answer – miky Oct 16 '13 at 15:06
  • While am try this, am getting this error, @android:style/Widget.Holo.ActionBar requires API level 11 (current min is 10). – jrh Apr 15 '14 at 06:52
  • 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? – GyRo Feb 22 '15 at 09:20
  • How is that supposed to work? Please add more details for a end-to-end solution. – Houman Oct 06 '20 at 15:00
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.

Christopher Perry
  • 38,891
  • 43
  • 145
  • 187
  • 3
    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? – mxk Mar 08 '12 at 11:22
  • 7
    Use useLogo|showHome instead of setting size to 0 – Jerome VDL Jul 21 '13 at 22:24
24

In your Manifest

<activity android:name=".ActivityHere"
     android:label="">
easycheese
  • 5,859
  • 10
  • 53
  • 87
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

Manohar
  • 22,116
  • 9
  • 108
  • 144
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();
Hamid
  • 1,493
  • 2
  • 18
  • 32
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.

Siqi Liu
  • 165
  • 3
  • 7
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

Milaaaad
  • 317
  • 6
  • 13
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

voucher_wolves
  • 565
  • 10
  • 20
3

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

<activity 
    android:name=".ActivityHere"
    android:label=""
>
Gab
  • 5,604
  • 6
  • 36
  • 52
3
getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().hide();

hope this will help

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);
Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
2

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

this.setTitle("");

in your Activity

Vaygeth
  • 156
  • 8
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.

eyoung100
  • 168
  • 9
  • 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. – AlwaysConfused Apr 05 '17 at 18:41
1

Simply extends your java file from AppCompatActivity and do this:

ActionBar actionBar = getSupportActionBar(); // support.v7
actionBar.setTitle(" ");
Harsh Prajapati
  • 510
  • 5
  • 7
1

Use the following:

requestWindowFeature(Window.FEATURE_NO_TITLE);
Baz
  • 36,440
  • 11
  • 68
  • 94
Vivek
  • 4,170
  • 6
  • 36
  • 50
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>
Opal
  • 81,889
  • 28
  • 189
  • 210
Damoon
  • 9
  • 1
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....

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.

Ray Chakrit
  • 404
  • 5
  • 7
-3
ActionBar actionBar = getActionBar();
actionBar.setTitle("");
Baz
  • 36,440
  • 11
  • 68
  • 94
Joe Lewis
  • 1,970
  • 2
  • 18
  • 20
  • 3
    @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. – user1234 Sep 14 '14 at 16:28