【发布时间】:2019-12-28 07:27:50
【问题描述】:
我使用 android studio 的 New->Activity->Settings Activity 创建了一个偏好 Activity,我想在其中切换 Dark/Light 主题。
<EditTextPreference
app:key="signature"
app:title="@string/signature_title"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="reply"
app:entries="@array/reply_entries"
app:entryValues="@array/reply_values"
app:key="reply"
app:title="@string/reply_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat
app:key="@string/theme"
app:title="@string/theme" />
现在,在我的主题中,我有: styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
</resources>
在连击状态下更改为暗/亮,而不是按钮状态。我怎样才能做到这一点?
我已经检查了this 问题,但很遗憾,我无法将app:id 添加到切换按钮以获取状态。
【问题讨论】:
标签: android