Reputation: 601
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>
Upvotes: 7
Views: 1857
Reputation: 83
Just add app:iconSpaceReserved="false"
line to your XML file and now there won't be any space from start.
Upvotes: 1
Reputation: 89
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);
Upvotes: 2
Reputation: 392
I think its due to the PreferenceThemeOverlay that you are using for that activity. Your selected style taking default padding from left or right.
use this code
<style name="" parent="PreferenceThemeOverlay">
<item name="android:paddingLeft">0dp</item>
<item name="android:paddingRight">0dp</item>
</style>
Upvotes: 0