在布局xml文件中,我使用@string设置属性,如下所示:
<com.hardpass.MyCustomComponent
android:layout_width="fill_parent"
android:layout_height="wrap_content"
mynamespace:title="@string/xxootitle" />
如何处理自定义组件@string/xxootitle
中的com.hardpass.MyCustomComponent
?
或者如何将@string/xxootitle
解析为在strings.xml中定义的实际值。
String title = attrs.getAttributeValue(mynamespace, "title");
//the title got here is "@string/xxootitle",
//but how to parse `@string/xxootitle` to the real value which is defined in strings.xml.
答案 0 :(得分:2)
使用getAttributeResourceValue和getString,
getString(attrs.getAttributeResourceValue(mynamespace, "title", R.string.xxootitle));