Android: how to hide ActionBar on certain activities

后端 未结 16 1836
遇见更好的自我
遇见更好的自我 2020-11-29 17:58

I\'ve developed a simple demo application with a splash screen a map and some regular screens.

I have an action bar at the top that contains a logo. It all looks fin

相关标签:
16条回答
  • 2020-11-29 18:22

    The above answers would help with the ActionBar thing. To add to it, use the following code in case you are using the Splash Screen: Use this before you set the content view:

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    

    Just to clarify, here's how you do it:

        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);         
        setContentView(R.layout.activity_main);
    

    This would make your screen a full screen, i.e remove the top bar where you see the network bar, etc

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

    As you are asking about how to hide in a certain activity, this is what you need :

    getSupportActionBar().hide(); 
    
    0 讨论(0)
  • 2020-11-29 18:25

    Add New Style in your style.xml

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    
    <style name="LoginTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    

    and then add following line in your manifest

    <activity android:name=".Login"
            android:label="@string/app_name"
            android:theme="@style/LoginTheme"
            >
    
    0 讨论(0)
  • 2020-11-29 18:27

    If you were using Theme.AppCompat.Light, a better equivalent would be Theme.AppCompat.Light.NoActionBar.

    I found that using Theme.AppCompat.NoTitleBar caused my button text to be invisible so I am using Theme.AppCompat.Light.NoActionBar.

    <activity android:name=".Activity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.AppCompat.Light.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    
    0 讨论(0)
  • 2020-11-29 18:28

    Apply the following in your Theme for the Activity in AndroidManifest.xml:

    <activity android:name=".Activity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    That should do the trick.

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

    The ActionBar usually exists along Fragments so from the Activity you can hide it

    getActionBar().hide();
    getActionBar().show();
    

    and from the Fragment you can do it

    getActivity().getActionBar().hide();
    getActivity().getActionBar().show();
    
    0 讨论(0)
提交回复
热议问题