Adding a custom layout to a PreferenceFragment

I have a preference fragment with a hierarchy of preferences screen. I would like to add a custom layout to define the "about the author" section by adding an image to the element and link (browser intent). I searched, but I did not find any resources on this topic.

+5
source share
1 answer

In your XML preferences file ( res/xml/prefs.xml ) add a Preference with a custom layout:

 <Preference android:layout="@layout/custom_preference"/> 

An example layout/custom_preference.xml with an ImageView and a TextView with a link that will open in a browser:

 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_book" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="http://www.mylink.com" android:autoLink="all"/> </LinearLayout> 

This is the last preference in the screenshot: user preferences screen

+10
source

Source: https://habr.com/ru/post/1259014/


All Articles