我知道这可能是重复的
Applying AppCompat theme to individual preferences in a PreferenceFragment
我在youtube上使用了此视频: https://www.youtube.com/watch?v=PS9jhuHECEQ
并且从devolper android获得此准则: https://developer.android.com/guide/topics/ui/settings
建立我的偏好。目前,我的偏好库是:
实现'androidx.preference:preference:1.1.0-beta01'
所以现在我想将我的主题应用于我的偏好设置...
我在manifest.xml中找到了这个
<application
android:name=".XXXApplication"
android:allowBackup="false"
android:label="@string/W_APP_NAME"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".Views.MainActivity"
android:label="@string/W_APP_NAME"
android:screenOrientation="landscape"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我的styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
现在,我有一个root_preferences.xml,其中包含其他几个首选项,如下所示:
root_preferences.xml
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Preference
app:title="@string/N_CAM_ITEM"
app:summary="@string/P_CAMERA_SETTINGS"
app:icon="@drawable/ic_menu_camera"
app:fragment="com.example.XXX.Views.CameraSettingFragment"/>
还有一个camera_preferences.xml,它也是一个PreferenceScreen
,包含SwitchPreferences
,依此类推...
如果我导航到设置,则会叫SettingsFragment
。
public class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
那么,我想念的是我的主题/样式未应用于这些首选项吗?希望你能帮我这个忙!
所以复选框和开关没有显示任何颜色...必须有一些主要的橙色绿色
答案 0 :(得分:0)
@Louis在评论ColorAccent
中指出,这是在首选项设置中实现彩色元素的一种方法。非常感谢路易斯!