2012-06-14 27 views
0

在佈局XML文件中,我將使用屬性@string這樣的:如何處理android自定義組件中的@string屬性?

<com.hardpass.MyCustomComponent 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    mynamespace:title="@string/xxootitle" /> 

如何應對自定義組件com.hardpass.MyCustomComponent@string/xxootitle? 或如何將@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. 

回答

2

使用getAttributeResourceValue和GetString,

getString(attrs.getAttributeResourceValue(mynamespace, "title", R.string.xxootitle));