【发布时间】:2021-05-30 11:30:14
【问题描述】:
致版主:这不是一个重复的问题。我已经尽力了。 StackOverflow 的解决方案。
我在 styles.xml 文件中使用了 Theme.MaterialComponents.Light.NoActionbar 作为父主题。
我的样式.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">#00000000</item>
<item name="snackbarStyle">@style/MySnackbar</item>
</style>
<style name="AppTheme2" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:navigationBarColor">#00000000</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="snackbarStyle">@style/MySnackbar</item>
</style>
</resources>
我的应用类代码:
public class Extendit extends Application {
@Override
public void onCreate() {
super.onCreate();
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
应用程序类附加在清单文件中。此外,AppTheme 是应用程序的基本主题。
androidmanifest.xml:
<application
android:name=".Extendit"
android:allowBackup="true"
android:appComponentFactory="df"
android:icon="@mipmap/iconx"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/iconx"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory">
我还在styles.xml 中添加了“forcedarkallowed”错误标志并删除了styles.xml(night) 文件。
附:我正在使用 Realme 设备。
【问题讨论】:
-
“我正在使用 Realme 设备”——您是否尝试过其他任何方法?也许 Realme 正在做一些不幸的事情。