Home > Back-end >  Why Action bar always stay as gray color in android?
Why Action bar always stay as gray color in android?

Time:10-11

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>

enter image description here

CodePudding user response:

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"/>

CodePudding user response:

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>

CodePudding user response:

in styles.xml :

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