的解決方案是利用Android的內置資源選擇系統。您應該指定兩種不同的樣式,並根據API版本將它們放在適當的文件夾中。請注意,以下示例不是我的,我從this教程中拿走它們。
res/values-v4/styles.xml
:
<resources>
<!-- Text for listboxes, inverted for Andorid prior to 3.0 -->
<style name="MyListTextAppearanceSmall">
<item name="android:textAppearance">?android:attr/textAppearanceSmallInverse</item>
</style>
<style name="MyListTextAppearanceDefault">
<item name="android:textAppearance">?android:attr/textAppearanceInverse</item>
</style>
<style name="MyListTextAppearanceMedium">
<item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item>
</style>
</resources>
res/values-v11/styles.xml
:
<resources>
<!-- Text for listboxes, non-inverted starting with Android 3.0 -->
<style name="MyListTextAppearanceSmall">
<item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
</style>
<style name="MyListTextAppearanceDefault">
<item name="android:textAppearance">?android:attr/textAppearance</item>
</style>
<style name="MyListTextAppearanceMedium">
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
</style>
</resources>
然後,在你TextView
,指定像這樣的風格:
<TextView
android:style="@style/MyListTextAppearanceSmall"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee" />
見上面掛了一個冗長的解釋教程。
這個問題還算舊,但也許別人會從中受益。解決方案是利用Android的內置資源選擇來實現您正在尋找的內容。有關說明,請參閱[本](http://kmansoft.com/2011/10/15/alertdialog-custom-listview-items-and-honeycomb/)教程。 – howettl
我在我的項目中使用了完全相同的方法,但希望有更好的解決方案。 – Michael
爲什麼我的答案被刪除? – howettl