How can I color the cutout/notch area with background color in non-full screen landscape mode in android jetpack compose

1.9k views Asked by At

In landscape mode in Night mode cutout area is rendered white, how can I set the black(background) color to it? My app is not in fullscreen/immersive mode.

I want to color white color cutout strip in black(background) color.

I want to color white color cutout strip in black(background) color

Edit :

The problem is caused by setting theme twice for splashscreen api, for application as well as activity

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.name.myapplication">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication.Starting"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:theme="@style/Theme.MyApplication"> 
            <!-- I added android:theme="@style/Theme.MyApplication.Starting" which was causing problem-->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Theme.MyApplication" parent="android:Theme.Material.Light.NoActionBar" />

    <style name="Theme.MyApplication.Starting" parent="Theme.SplashScreen">
        // Set the splash screen background, animated icon, and animation duration.
        <item name="windowSplashScreenBackground">@color/black</item>

        // Use windowSplashScreenAnimatedIcon to add either a drawable or an
        // animated drawable. One of these is required.
        <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
        <item name="windowSplashScreenAnimationDuration">1000</item>  # Required for
        # animated icons and only works for android 12 and above.

        // Set the theme of the Activity that directly follows your splash screen.
        <item name="postSplashScreenTheme">@style/Theme.MyApplication</item>  # Required.
    </style>

</resources>

MainActivity.kt

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        installSplashScreen()
        setContent {
            MyApp()
        }
    }
}

I still want to know how to set color for cut out area if possible.

1

There are 1 answers

2
Atakan Yildirim On

You can use windowLayoutInDisplayCutoutMode attr in your theme.xml

<item name="android:windowLayoutInDisplayCutoutMode">default</item>

You can also replace the value with "shortEdges", "never" or "always".

See this doc: https://developer.android.com/guide/topics/display-cutout