AndroidDeveloperLB/MaterialPreferenceLibrary

Icon Padding

Closed this issue · 7 comments

Can we change the padding or margin of icon ?

Pretty sure I've made it like on the standard one of Android, but if you are not happy with it, you can change the layout.
You can do it either by any of those options:

  1. edit the original "mpl__preference.xml" file
  2. create your own copy of "mpl__preference.xml" and then edit it. Your copy should automatically replace the one of the library.
  3. do it via code, by extending the preference you wish to customize, and then change it for the view with id android.R.id.icon .

This is true for any kind of customization of the preferences layout.

1,2 not working

What exactly have you tried? Also, have you considered using margins instead?

  1. cant edit generated .xml file of library
  2. created my own copy and it didnt auto replace .xml
  1. you are not supposed to edit generated xml files. You are supposed to edit the original file.

  2. it must have the exact name, and in the layout folder of your project. I've just tested it now. It works fine.
    Here's what I did to the sample project:
    a. added the file 'mpl__preference.xml" into the layout folder, and put there a huge padding for the icon:

    <com.lb.material_preferences_library.internal.widget.PreferenceImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxHeight="48dp"
        android:maxWidth="48dp"
        android:padding="20dp"
        />
    

b. edited the "settings_example.xml" and added to one of the preferences the icon:

    <com.lb.material_preferences_library.custom_preferences.ListPreference
        android:defaultValue="dark"
        android:key="@string/pref_theme"
        android:summary="%s"
        android:title="Theme"
        app:dialogTitle="dialog title"
        app:entries="@array/pref_theme_list_entries"
        app:entryValues="@array/pref_theme_list_values"
        app:icon="@android:drawable/sym_def_app_icon"/>

And the result:
device-2015-08-22-120021

I am using gradle to use library, so how do i edit the original file? I don't think i can do that. Probably second option didn't also work for that reason, maybe i should download and copy library files into project.

#1 is obviously impossible if using gradle , as you need to edit the original file.
#2 is still possible.
and of course, #3 is always possible.

If you wish, send me an email, and I will email you with a working sample that shows #2 is possible.