Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android preference fragment taking space for icon in list preference fragment

enter image description here

As you can see in the image, it is taking some additional space in left . Later I have found that this space is assigned for icon. How can I remove this space?

I have tried preference.setIcon(null);

Also I have tried the solution given here . But no luck .

I am using compile 'com.android.support:preference-v7:25.1.1'

Edit

Here is my style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="preferenceTheme">@style/PreferenceThemeOverlayCustom</item>
</style>

<style name="PreferenceThemeOverlayCustom" parent="PreferenceThemeOverlay">
    <item name="preferenceFragmentListStyle">@style/PreferenceFragmentListCustom</item>
</style>

<style name="PreferenceFragmentListCustom" parent="PreferenceFragmentList">

    <item name="android:paddingEnd">0dp</item>
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">0dp</item>
    <item name="paddingStart">0dp</item>
</style>
like image 883
mSapps Avatar asked Feb 22 '17 10:02

mSapps


1 Answers

Constructing the new preference like this:

new Preference(getPreferenceScreen().getContext());

should solve the issue.

As mentioned by guillaume-tgl the explanation can be found here.

Edit: Using the new support library (28.0.0) you should also call:

preference.setIconSpaceReserved(false);

like image 95
Julian Eggers Avatar answered Sep 28 '22 19:09

Julian Eggers