简体   繁体   中英

Why Action bar always stay as gray color in android?

AndroidManifest.xml:

I have video player, everything works, but I do not know how to remove gray navbar, even I declared in manifest

android:theme="@style/Theme.AppCompat.Light.NoActionBar"

And idea?

   <activity
    android:name=".activity.MainActivity"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">

  </activity>

在此处输入图像描述

if you are using AppCompatActivity , you need to add new theme

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

in AndroidManifest.xml file:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"/>

in styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Lite.NoActionBar">
     ...
     ...
</style>

How about if you use this code inside theme.xml or styles.xml

<resources xmlns:tools="http://schemas.android.com/tools">
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="android:windowBackground">@color/white</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="windowNoTitle">true</item>
    </style>
</resources>

Then inside the Manifest File instead of applying the theme inside the activity tag like this.

<activity
            android:theme="@style/AppTheme"
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter> 
...
</activity>

You apply the theme inside the Application Tag instead

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
       >
        <activity
            android:name=".MainActivity"
            android:exported="true">

              ....
        </activity>
    </application>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM