2016-04-01 21 views
1

我試圖擴大Android的simple_list_item_2屬性,所以我複製它的XML,它是:Android的訪問SDK中的XML

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?attr/listPreferredItemHeight" 
    android:mode="twoLine" 
    android:paddingStart="?attr/listPreferredItemPaddingStart" 
    android:paddingEnd="?attr/listPreferredItemPaddingEnd"> 

    <TextView android:id="@id/text1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="8dp" 
     android:textAppearance="?attr/textAppearanceListItem" /> 

    <TextView android:id="@id/text2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/text1" 
     android:layout_alignStart="@id/text1" 
     android:textAppearance="?attr/textAppearanceListItemSecondary" /> 

</TwoLineListItem> 

的問題是,在我的實現,該行

android:textAppearance="?attr/textAppearanceListItemSecondary"/> 

給出了錯誤:

Cannot resolve symbol ?attr/textAppearanceListItemSecondary

我試過的東西LIK E:

android:textAppearance="android:?attr/textAppearanceListItemSecondary"

android:textAppearance="@android?attr/textAppearanceListItemSecondary" ,但它不工作

所以我的問題是,我怎麼能訪問相同的符號/屬性,在Android SDK中資源佈局可以訪問?我是否需要將該符號複製到我的應用程序目錄中,或者我可以簡單地訪問simple_list_item_2所做的那個符號嗎?

而且,原來simple_list_item_2位於C:\Android\sdk\platforms\android-23\data\res\layout\和我實現它位於\app\src\main\res\layout如果它可以幫助

+0

哎,我只是用Google搜索這個,來到這裏,然後意識到這是我自己問題,我去年問了 – Parker

回答

2
android:textAppearance="?android:attr/textAppearanceListItemSecondary" 

Documentation

你需要把?包名之前,而不是之後:?[<package_name>:][<resource_type>/]<resource_name>

Referencing style attributes
A style attribute resource allows you to reference the value of an attribute in the currently-applied theme. Referencing a style attribute allows you to customize the look of UI elements by styling them to match standard variations supplied by the current theme, instead of supplying a hard-coded value. Referencing a style attribute essentially says, "use the style that is defined by this attribute, in the current theme."

To reference a style attribute, the name syntax is almost identical to the normal resource format, but instead of the at-symbol (@), use a question-mark (?), and the resource type portion is optional. For instance:

?[<package_name>:][<resource_type>/]<resource_name>

+1

添加一些解釋和答案如何這個答案幫助OP在修復當前問題 –

+0

嗨Соколов,並歡迎來到堆棧溢出!關於你的答案;你的代碼可能是正確的,但是在某些情況下,它會作出更好的回答;例如,您可以解釋如何以及爲什麼這個提議的變更可以解決提問者的問題,或許還包括指向相關文檔的鏈接。這將使它對他們更有用,而且對尋求類似問題解決方案的其他網站讀者也更有用。 –

0

您不能訪問私有SDK的屬性,所以你必須複製它們。

它可能在代碼中使用反射,但肯定不在xml中。