6

プロジェクトでアクションバーとナビゲーション ドロワーを使用しています。appcompat v7 および v4 を使用します。

appcompat v7 WITH リソースを追加しました。

以下は、Creating a Navigation Drawerにある Android サンプル アプリから直接取得したナビゲーション ドロワー リストのテキストビューです。

下の 3 行はすべて、アプリケーションが失敗する原因です。問題なくビルドできますが、強制的にクローズされ、問題の解決方法がわかりません。リソースに appcompat を追加したことを考えると、属性が見つからない理由がわかりません。それとも、appcompat などで有効ではありませんか?

MinSDK バージョンは 10 で、コードが失敗します。API 10 以上では、コードは正常に動作します。

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"        
    android:gravity="center_vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:textColor="#fff"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
4

2 に答える 2

10

互換性ライブラリで定義されている値を使用できます。これは、listChoiceBackgroundIndicator を選択した背景以外のすべてを指定しますが、他のものを使用することもできます。

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:textColor="#fff"
    android:background="?attr/listChoiceBackgroundIndicator"
    android:minHeight="?attr/listPreferredItemHeightSmall"/>
于 2014-02-24T13:09:57.697 に答える
2

私は同じ問題を抱えていました。私が理解しているように、古いAPIにはtextAppearanceListItemSmall、activeBackgroundIndicator、およびlistPreferredItemHeightSmallが事前定義されていません。したがって、必要に応じて独自の値を指定するか、この行を削除して運に頼ることができます。

于 2013-08-15T09:47:33.213 に答える