3

I'd like to implement a custom Preference with an icon and be able to define the source of the icon in the XML specification of the view. If I do

<com.example.MyIconPreference
    android:src="@drawable/icon1"
    android:key="test_key"
    android:title="@string/pref_title"
    android:summary="@string/pref_summary"
></com.example.MyIconPreference>

How can I retrieve programmatically the drawable resource or identifier?

Thanks

Caroline
  • 3,445
  • 5
  • 16
  • 25

2 Answers2

0

This is identical to how you can define your custom View and custom View attributes. The mechanism is the same.

You can find an example with View here: Creating Custom Views.

inazaruk
  • 72,103
  • 23
  • 181
  • 156
0

Define it similar to a custom view and retrieve attributes in you implementation.

This question discuss how to do this for custom views: Declaring a custom android UI element using XML

Community
  • 1
  • 1
Saad Farooq
  • 12,612
  • 9
  • 64
  • 94