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

后端 未结 20 2110
傲寒
傲寒 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 18:01

    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.

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

    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.

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

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

    <activity 
        android:name=".ActivityHere"
        android:label=""
    >
    
    0 讨论(0)
  • 2020-11-29 18:12

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

    In your Manifest

    <activity android:name=".ActivityHere"
         android:label="">
    
    0 讨论(0)
  • 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.

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