How do you remove the title text from the Android ActionBar?

后端 未结 20 2108
傲寒
傲寒 2020-11-29 17:17

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

相关标签:
20条回答
  • 2020-11-29 17:55

    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.

    0 讨论(0)
  • 2020-11-29 17:55

    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();
    
    0 讨论(0)
  • 2020-11-29 18:00

    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);
    
    0 讨论(0)
  • 2020-11-29 18:00

    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>
    
    0 讨论(0)
  • 2020-11-29 18:01

    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

    0 讨论(0)
  • 2020-11-29 18:01

    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

    0 讨论(0)
提交回复
热议问题