禁用java黑暗模式在安卓应用程序中不起作用
我创建了一个安卓应用程序,当我把它下载到手机上时,它出现在黑暗模式下
我希望我的应用程序始终处于灯光模式,因此我使用了以下选项:
super.onCreate(savedInstanceState);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
但它仍然在黑暗模式下向我展示了应用程序
我怎样才能完全禁用它
我的风格。xml文件是:
<style name="CustomActivityTheme" parent="@style/Theme.AppCompat.Light">
<item name="安卓:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="安卓:windowActionBarOverlay">true</item>
<!-- other activity and action bar styles here -->
</style>
<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="安卓:background">@color/colorGraySearchText</item>
<item name="background">@color/colorGraySearch</item>
<item name="安卓:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="安卓:subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<!-- Text -->
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@安卓:style/TextAppearance">
<item name="安卓:textColor">@color/colorGraySearchText</item>
<item name="安卓:textSize">16dp</item>
</style>
<style name="CustomActivityTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="CustomActivityTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="CustomActivityTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
解决方案:
以下步骤解决了我的问题:
改变我的身材。渐变(应用程序)至:
compileSdkVersion 29
targetSdkVersion 29
将以下行添加到“我的样式”中的任何样式。xml:
<item name="安卓:forceDarkAllowed" tools:targetApi="q">false</item>
多谢各位
共 (0) 个答案