Retrieve XML attributes of a view in Android
I'd like to implement a custom Preference with an icon and be able 开发者_如何学Pythonto 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
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.
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
精彩评论