在夜间模式的横向模式下,剪切区域呈现白色,如何将其设置为黑色(背景)颜色?我的应用程序未处于全屏/沉浸模式。
我想将白色剪纸条涂成黑色(背景)颜色。
编辑:
该问题是由于为 splashscreen api、应用程序和 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>
主题.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()
}
}
}
如果可能的话,我仍然想知道如何设置剪切区域的颜色。
您可以在 theme.xml 中使用
windowLayoutInDisplayCutoutMode
attr
<item name="android:windowLayoutInDisplayCutoutMode">default</item>
您还可以将该值替换为“shortEdges”、“never”或“always”。
请参阅此文档:https://developer.android.com/guide/topics/display-cutout
即使与
也有同样的问题<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
二手
如果您不需要根据聚焦的屏幕进行不同的处理,如果这只是颜色问题,我设法使用以下方法来做到这一点:
<item name="android:background">#FF0000</item>
在我的主题.xml中