Android windowBackground 属性被忽略
Android windowBackground attribute being ignored
或者有点。
我有一个带有片段容器的 activity。每个 Fragments 布局本身没有背景。我已经尝试将背景设置为透明 - 没有效果。
我还使用 FragNav library 来处理片段交易。
问题是 - widnows 背景 在编辑器 xml 预览中正确显示。
风格:
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@drawable/ng_window_background</item>
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>
Drawable“ng_windows_background”只是一个纯色的形状。十六进制颜色为 #FDA23。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/colorAccent"/>
</shape>
XML preview example:背景颜色为橙色。
Screenshot from device如您所见,背景颜色为灰色。
我已经尝试过的:
- 更改片段的布局背景(android:背景)颜色。是的,它 有效 ,但它会导致透支效果,我正在 试图通过使用 android:windowBackground 属性来避免。
- 使用 android:colorBackground 属性,由于 material 组件建议。没有效果。
- 正在以编程方式和清单中更改应用的主题。没有效果。
- 正在将 Theme.MaterialComponents.NoActionBar 更改为 AppCompat。没有效果 + 由于某些问题我无法使用 AppCompat。
- 通过 getWindow().setBackgroundResource() 更改背景;既不在 OnResume();
我猜这是 MaterialComponents 库的问题。我猜。
'必要时可以显示任何代码。
编辑:清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="packageName"
>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="AppClassPath"
android:allowBackup="true"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/logo_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=SplashScreenPath
android:theme="@style/AppTheme.Launcher">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name=MainActivityPath />
</application>
</manifest>
编辑#2:
删除了所有功能,将 OnCreate() 留空。没有效果,所以外部库没有问题。
帮助
好的,问题出在名为 'com.infideap.drawerbehavior:drawer-behavior:1.0.1' 的外部库上。将尝试找出问题所在并 post 一个合适的 solution.Yeah.
或者有点。
我有一个带有片段容器的 activity。每个 Fragments 布局本身没有背景。我已经尝试将背景设置为透明 - 没有效果。 我还使用 FragNav library 来处理片段交易。
问题是 - widnows 背景 在编辑器 xml 预览中正确显示。
风格:
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@drawable/ng_window_background</item>
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>
Drawable“ng_windows_background”只是一个纯色的形状。十六进制颜色为 #FDA23。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/colorAccent"/>
</shape>
XML preview example:背景颜色为橙色。
Screenshot from device如您所见,背景颜色为灰色。
我已经尝试过的:
- 更改片段的布局背景(android:背景)颜色。是的,它 有效 ,但它会导致透支效果,我正在 试图通过使用 android:windowBackground 属性来避免。
- 使用 android:colorBackground 属性,由于 material 组件建议。没有效果。
- 正在以编程方式和清单中更改应用的主题。没有效果。
- 正在将 Theme.MaterialComponents.NoActionBar 更改为 AppCompat。没有效果 + 由于某些问题我无法使用 AppCompat。
- 通过 getWindow().setBackgroundResource() 更改背景;既不在 OnResume();
我猜这是 MaterialComponents 库的问题。我猜。
'必要时可以显示任何代码。
编辑:清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="packageName"
>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="AppClassPath"
android:allowBackup="true"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/logo_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=SplashScreenPath
android:theme="@style/AppTheme.Launcher">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name=MainActivityPath />
</application>
</manifest>
编辑#2: 删除了所有功能,将 OnCreate() 留空。没有效果,所以外部库没有问题。
帮助
好的,问题出在名为 'com.infideap.drawerbehavior:drawer-behavior:1.0.1' 的外部库上。将尝试找出问题所在并 post 一个合适的 solution.Yeah.