2013-07-13 92 views
8

你好我已經創建使用ActionBar Sherlockandroid support Library v4舊版本compatbility(我的應用程序的的minSdkVersion =「8」)中,我已經使用了TextView的某些屬性在ListView控件與ListView的導航抽屜式導航:抽屜式導航欄的Android API的具體佈局屬性

<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 Sherlock的?attr/activatedBackgroundIndicator。但是我沒有發現其他兩個屬性的任何等價。在行動吧Sherlock中有?attr/textAppearanceListItemSmall,但它沒有正常工作。

那麼這些屬性的等價性是如何提供支持2.1以上的所有API?

回答

2

我不確定你是否真的需要使用android尺寸(例如listPreferredItemHeightSmall等)在某些android版本中,可以將這個尺寸設置爲12並在其他14個尺寸。我建議你創建自己的尺寸,這將用於您的整個應用程序,並且您可以在需要更改時輕鬆編輯它們。

+0

你好,我已經通過設置 '<捫名= 「textview_height」> 50dp <捫名= 「FONT_SIZE」> 18SP' 非常感謝解決它! :) –

+2

也是一個問題。這個自定義維度看起來很完美。但是這些尺寸是否因android標準尺寸而異?我的意思是,這個尺寸的android API的值是什麼? –

+1

你可以在android sdk中找到這些尺寸。如果尺寸不同,如果您的佈局看起來像您想要的並且您遵循android設計模式,則無關緊要。 – koso

31

爲了支持低版本,而不是刪除以下三個參數,

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

您還可以在值中創建API特定的樣式,values-v11 e t.c. –

+1

我認爲在步驟b中需要一些更正。這些名稱不匹配。 – ooolala