您好,我使用 ActionBar Sherlock
和 android support Library v4
创建了一个带有 ListView 导航的抽屉导航,以实现旧版本兼容性(我的应用程序的 minSdkversion="8"),其中我在 ListView 中为 textview 使用了一些属性:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="5dp"
android:textColor="#fff"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
这显示错误,因为 ?android:attr/activatedBackgroundIndicator
来自 API 11 和 ?android:attr/textAppearanceListItemSmall
& ?android:attr/listPreferredItemHeightSmall
来自 API 14。
我设法支持 ?android:attr/activatedBackgroundIndicator
,方法是用 actionBar Sherlock 的 ?attr/activatedBackgroundIndicator
替换它。但我没有发现其他两个属性有任何等价关系。在 actionBar Sherlock 中有 ?attr/textAppearanceListItemSmall
但它不能正常工作。
那么这些属性的等效项是什么以提供对 2.1 以上所有 API 的支持?
最佳答案
为了支持低版本,不去掉下面三个参数,
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
您实际上可以用等效的值/资源替换它们。
等效值可以从 https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml
现在,
a)
android:textAppearance="@android:style/TextAppearance.Medium"
b)
在上面的工程中浏览hdpi,mdpi等资源,得到名为list_activated_holo.9.png
的文件
最后
android:background="@drawable/list_item_activated_background"
c) 从得到的等效值,我们知道listPreferredItemHeightSmall是48dip
android:minHeight="48dip"
关于android - 抽屉导航 Android API 特定的布局属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17629696/