特定于Android API的导航布局属性
您好,我已经使用特定于Android API的导航布局属性,android,api,layout,Android,Api,Layout,您好,我已经使用ActionBar Sherlock和android支持库v4创建了一个带有ListView导航的导航抽屉,以实现旧版本兼容性(我的应用程序的minSdkversion=“8”),其中我在ListView中使用了textview的一些属性: <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/title" android:la
ActionBar Sherlock
和android支持库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,从而成功地支持了?android:attr/activatedBackgroundIndicator。但是我没有发现其他两个属性的等价性。actionBar Sherlock中有?attr/textAppearanceListItemSmall
,但它工作不正常
那么,为支持2.1以上的所有API,这些属性的等价性是什么呢 我不确定您是否真的需要在某些android版本中使用android维度(如listPreferredItemHeightSmall
等),该维度是否可以是12,其他14。我建议您创建自己的维度,它将在整个应用程序中使用,您可以在需要更改时轻松编辑它们。要支持较低版本,而不是删除以下三个参数
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
实际上,您可以用等价的值/资源替换它们
等效值可从以下公式获得:
现在,
- a)
android:textAppearance=“@android:style/textAppearance.Medium”
- b)
- 从下载选择器
- 在上面的项目中,浏览hdpi、mdpi等中的资源,并获取名为list\u activated\u holo.9.png的文件
- 最后
android:background=“@drawable/list\u item\u activated\u background”
c)根据获得的等效值,我们知道listPreferredItemHeightSmall为48dip
android:minHeight=“48dip”
您好,我通过设置50dp 18sp
非常感谢!:)还有一个问题。这个自定义维度看起来很完美。但这些维度是否与android标准维度不同?我的意思是,这个维度的android API值是多少?你可以在android sdk中找到这些维度。尺寸是否不同、布局是否符合您的要求以及是否遵循android设计模式都无关紧要。您还可以在values-v11 e t.c中创建API特定样式。我认为在步骤b中需要进行一些更正。这些名字不匹配。