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
我想用图标实现自定义首选项,并能够在视图的XML规范中定义图标的来源。如果我做
<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
谢谢
2 个解决方案
#1
0
This is identical to how you can define your custom View
and custom View
attributes. The mechanism is the same.
这与您定义自定义View和自定义View属性的方式相同。机制是一样的。
You can find an example with View
here: Creating Custom Views.
您可以在此处查看示例:创建自定义视图。
#2
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
此问题讨论如何为自定义视图执行此操作:使用XML声明自定义Android UI元素
#1
0
This is identical to how you can define your custom View
and custom View
attributes. The mechanism is the same.
这与您定义自定义View和自定义View属性的方式相同。机制是一样的。
You can find an example with View
here: Creating Custom Views.
您可以在此处查看示例:创建自定义视图。
#2
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
此问题讨论如何为自定义视图执行此操作:使用XML声明自定义Android UI元素