2.在SettingActivity中:
protected void onCreate(Bundle savedInstanceState)
{
//TODO
SharedPreferences sp = getPreferences(Context.MODE_PRIVATE);
boolean isNight = sp.getBoolean("isNight", false);
if (isNight)
{
setTheme(R.style.night);
} else
{
setTheme(R.style.light);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
*3.清单中:
android:name="com.xinbo.app.BaseApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/light" >
4.style中:
<style name="light" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionbar_bg">@color/actionbar_bg</item>
<item name="left_head">@drawable/left_head_1</item>
<item name="left_list">@color/white</item>
<item name="card_bg">@color/white</item>
<item name="textcoler">@color/background_floating_material_dark</item>
<item name="set_list_bg_coler">@color/white</item>
<item name="set_bg_coler">@color/material_grey_100</item>
</style>
<style name="night" parent="Theme.AppCompat.NoActionBar">
<item name="actionbar_bg">@color/actionbar_bg_night</item>
<item name="left_head">@drawable/left_head_2</item>
<item name="left_list">@color/background_floating_material_dark</item>
<item name="card_bg">@color/background_floating_material_dark</item>
<item name="textcoler">@color/white</item>
<item name="set_list_bg_coler">@color/black</item>
<item name="set_bg_coler">@color/background_floating_material_dark</item>
</style>
求教,是哪里出问题了吗?怎么切换日夜间模式没效果
我试了一下,你的这个写法是对的,应该是是你的theme自定义有问题。建议排查theme
多谢,我有试过单独在activity中测试是可行,但整合在程序中,通过侧滑界面打开就没效果,manifest中设置如下:能帮看下还可以从哪找问题吗?
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/light" >
<activity
android:name="com.example.ex25_highgrade_day2_01.SettingActivity"
android:label="@string/title_activity_setting" >
</activity>