开发者

Retrieve XML attributes of a view in Android

开发者 https://www.devze.com 2023-03-28 09:17 出处:网络
I\'d like to implement a custom Preference with an icon and be able 开发者_如何学Pythonto define the source of theicon in the XML specification of the view. If I do

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

0

精彩评论

暂无评论...
验证码 换一张
取 消