导航抽屉 Android API 特定布局属性

9

你好,我用ActionBar SherlockAndroid支持库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。
我已经通过将其替换为actionBar Sherlock的?attr/activatedBackgroundIndicator来支持?android:attr/activatedBackgroundIndicator。但是我没有找到其他两个属性的等效项。在actionBar Sherlock中有?attr/textAppearanceListItemSmall,但它不能正常工作。
那么这些属性的等效项是什么,以支持2.1以上的所有API?
2个回答

32
为支持较低版本,不要删除以下三个参数。
  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获取。

现在,


2
你也可以在values、values-v11等中创建特定于API的样式。 - Eugene Smykov
1
我认为步骤b需要进行一些更正。这些名称不匹配。 - ooolala

2

我不确定你是否真的需要使用安卓尺寸(比如listPreferredItemHeightSmall等)。在某些安卓版本中,这个尺寸可能是12,在另一些版本中则是14。我建议你创建自己的尺寸,在整个应用中使用,并且可以在需要时轻松编辑。


你好,我已经通过设置以下代码解决了问题:50dp 18sp非常感谢! :) - Kaidul
2
另外还有一个问题。这个自定义维度看起来很完美。但是,这些维度和安卓标准维度有所不同吗?我的意思是,这些维度在安卓 API 中的数值是多少呢? - Kaidul
1
您可以在Android SDK中找到这些尺寸。如果您的布局看起来符合您的要求并遵循Android设计模式,那么尺寸不重要。 - Koso

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接