1

在夜间模式中的横向模式下,剪切区域呈现为白色,如何设置黑色(背景)颜色?我的应用程序未处于全屏/沉浸式模式。

我想用黑色(背景)颜色为白色剪纸条上色。

我想用黑色(背景)颜色为白色剪切条着色

编辑 :

问题是由两次为splashscreen api设置主题引起的,应用程序和活动

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>

主题.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()
        }
    }
}

如果可能的话,我仍然想知道如何为剪切区域设置颜色。

4

1 回答 1

1

您可以windowLayoutInDisplayCutoutMode在 theme.xml 中使用 attr

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

您也可以用“shortEdges”、“never”或“always”替换该值。

请参阅此文档:https ://developer.android.com/guide/topics/display-cutout

于 2022-02-03T11:13:08.960 回答