How to display a circular icon
Closed this issue · 4 comments
Can make this control can display a circular image, like "cricleimageview" ?
<Preference
android:icon="@drawable/xxx"
android:persistent="false"
android:summary="This is a preference with icon"
android:title="Preference 3" />
If you create a new layout for the preferences, you can use a circular image as icon. To do this, you need to create the layout XML (basically copy it and change the parts you want to change) and use it in the preference by setting the android:layout
attribute or by overriding it in your styles. You can find the layout files here, the basic one is preference_material.xml
which is used for most of the preferences, but there are some others used for specific ones (like preference_dropdown_material.xml
for the DropDownPreference
). Copy whichever you want to change, look for the PreferenceImageView
(id=@android:id/icon
) and replace it with your stuff. Make sure you use the same ID as the Preference
class will look for that when setting the icon. The view you want to use as a replacement must extend ImageView
and have a setImageDrawable(Drawable)
method for setting the image.
If you have the XMLs, you have 3 choices to use them:
Option 1
Save the modified XML files with the same name to the same folders. This way your XMLs will essentially replace the library XMLs, so you don't have to do anything else and it is applied globally.
Option 2
Use the android:layout
attribute on the appropriate preferences.
<Preference
android:icon="@drawable/xxx"
android:layout="@layout/your_modified_layout"
android:persistent="false"
android:summary="This is a preference with icon"
android:title="Preference 3" />
Option 3
Modify the preference styling by overriding the preferenceTheme
item in your app theme. This is really complex so if you want to do this, look up on the Internet how you can modify styles and attributes of styles.
Thank you very much, I decided to use the program 2. If can add custom properties in "Preference", such as: app: roundIcon = "@ drawable / xxx", It will save away a lot of code
It's not going to happen, and there are 2 very good reasons for that:
- I should create a new class extending
Preference
, then create all of the preferences extending this new class. This is really cumbersome, and again as I told you in the #92 issue, this would make the lib size bigger and the updates slower. - This is not a functionality that belongs to the preferences lib. This is a design question that is unique to every single app. Let's say you want this, but someone else wants 3D icons, again others want everything upside down, and this could go on for a long time. The role of this lib is to provide the preferences lib with the material design bug fixed and that's all it does. That's another thing that there are new preference types not part of the original lib, but those are still inside the role boundaries.
Okay