Android: How to adjust Margin/Padding in Preference?

前端 未结 5 1538
长情又很酷
长情又很酷 2020-12-08 22:26

Before I asked to remove the padding of the PreferenceActivity/PreferenceFragment:

Android: How to maximize PreferenceFragment width (or get rid of margin)?

5条回答
  •  误落风尘
    2020-12-08 23:05

    If you are creating preferences dynamically pass ContextThemeWrapper as a parameter to the new Preference

    TypedValue themeTypedValue = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, themeTypedValue, true);
    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getActivity(), themeTypedValue.resourceId);
    Preference preference = new Preference(contextThemeWrapper);
    

    I have found it in this article: Dynamically creating Preference Screens on Android

提交回复
热议问题