10

I would like to use textview in PreferenceScreen, it's a longer text that explains some specific setting. If I use summary or title attribute on some versions it gets formatted weirdly, doesn't display correctly etc. (The text is rather long).

Therefor I find it would be the best to use textview, is it possible to create custom settings element?

Badr Hari
  • 8,114
  • 18
  • 67
  • 100

3 Answers3

29

Use this:

<Preference
        android:selectable="false"
        android:enabled="true"
        android:key="example_key"
        android:title="example_title"
        android:summary="anything_you_want" />

The attributes selectable will decide the click action of the Preference.

developer033
  • 24,267
  • 8
  • 82
  • 108
zackygaurav
  • 4,369
  • 5
  • 26
  • 40
12

You can assign layout resource for your preference in your xml file, using tag android:layout="@layout/your_pref_layout".

Don't forget to use proper ids in your layout (android:id="@+android:id/title", android:id="@+android:id/summary") to assign views to be used as title/summary views.

For more info see for example this: Creating a custom layout for preferences

or this: How to add a button to PreferenceScreen

Community
  • 1
  • 1
Berťák
  • 7,143
  • 2
  • 29
  • 38
  • Yes, thank you, I did that. Now I have problem that I don't know how to assing proper height for my new element... wrap_content, fill_parent etc not working, most of the text is missing, since its long paragraph. – Badr Hari Aug 20 '13 at 11:32
  • I would try wrap_content..did you also assign the textview to be multiline (by defining maxLines/singleLine=false)? – Berťák Aug 20 '13 at 11:39
0

Yes You can create a layout and use that layout file to inflate as your preference screen you can see a example here.

custom EditTextPreference: can't get TextView by id

Community
  • 1
  • 1
Rajnish Mishra
  • 826
  • 5
  • 21