开始接触Google支持库的新更新,我想实现Theme.AppCompat.DayNight进入我的应用程序.
我遇到的问题是,似乎没有人解释如何自定义它.所以,如果我想要colorAccent一天与另一个不同的夜晚,我该怎么做?你应该指定不同的黑暗和光明主题吗?提前致谢!
android android-appcompat android-theme android-support-library
我正在使用新Theme.AppCompat.DayNight添加的Android Support Library 23.2
在Android 5.1上运行良好.
在Android 6.0上,活动看起来像使用灯光主题,但对话框看起来使用黑暗主题.
我的应用类:
public class MyApplication extends Application {
static {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_YES);
}
}
Run Code Online (Sandbox Code Playgroud)
我的styles.xml
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Dialog.Alert" parent="Theme.AppCompat.DayNight.Dialog.Alert"/>
Run Code Online (Sandbox Code Playgroud)
我的代码显示一个对话框:
new AlertDialog.Builder(mContext, R.style.Dialog_Alert)
.setTitle("Title")
.setMessage("Message")
.show();
Run Code Online (Sandbox Code Playgroud) xml android android-layout android-theme android-support-library