Override the layout used for preference in preference. Active / Preferred Themed Screen

I have an Activity preference in my application, and I tried to set a preference style using the following topic:

<?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyPreferenceTheme" parent="android:Theme.Translucent"> <item name="android:preferenceStyle">@style/MyPreference</item> <item name="android:windowBackground">@color/transparent_black</item> </style> <style name="MyPreference" parent="@android:style/Preference"> <item name="android:layout">@layout/preference</item> </style> <color name="transparent_black">#BB000000</color> 

So, I know that the theme loads when the background is correctly colored. However, my custom preferenceLayout (res / layout / preference.xml) does not apply to any preferences inside my preference setting.

Is this the right way to achieve preference? or am I missing something? Thanks in advance:)

+4
source share
2 answers

I found that it is better not to use parent = "android: style / Preference", as it does not seem to apply the style I'm trying to override. Create your layout you are using (@ layout / preference) and drop the inheritance from the android: style / Preference style. It worked for me when I had to do the same.

so this should be:

 <style name="MyPreference"> <item name="android:layout">@layout/preference</item> </style> 

Good luck

+4
source

This is mistake. See this problem .

You can “fix” it by assigning an identifier for each PreferenceScreen. Then you do this for each:

 ((PreferenceScreen) preferenceScreen).getDialog().getWindow().setBackgroundDrawable(drawable); 

Good luck
Tom

0
source

Source: https://habr.com/ru/post/1341560/


All Articles