我正在尝试扩展 Android 的 simple_list_item_2
,因此我复制了它的 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"/>
给出错误:
无法解析符号?attr/textAppearanceListItemSecondary
我尝试过类似的东西:
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
如果有帮助
最佳答案
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
您需要放置 ?
在包名称之前,而不是之后: ?[<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>
关于Android 访问 XML 中的 SDK 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36364873/