アンドロイドのサポートv7が私のアプリケーションに含まれていても
追加 android:background="?android:attr/selectableItemBackground"`を追加した。
を追加すると、私のIDEであるEclipseは、selectableItemBackgroundがmin Api 11以上のみであることを通知してエラーを投げます(コンパイルができません)。
XMLで背景にこの属性を追加するにはどうすればよいですか?
上位ライブラリからのコピー&ペーストは解決策ではないと仮定してください。
selectedItemBackgroundです。platforms/android-14/data/res/themes.xmlにあります。
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:state_window_focused="false" android:drawable="@color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true" android:drawable="@drawable/list_selector_background_focused" />
<item android:drawable="@color/transparent" />
</selector>
また、drawablesはAndroid SDKのディレクトリにあります。
../platforms/android-14/data
専門家ではありませんが、プラットフォームバージョンに基づいたテーマ設定が必要なようです。オフィシャルガイド](http://developer.android.com/guide/topics/ui/themes.html#SelectATheme)はこのプロセスをよく説明していると思います。
バージョンごとに異なるXMLファイルを作成し、res/values-v7
、res/values-v11
などに保存します。そして、それらのスタイルをビューに使用します。こんな感じです:
res/values-v7`に保存する:
<style name="LightThemeSelector" parent="android:Theme.Light">
...
</style>
in res/values-v11
:
<style name="LightThemeSelector" parent="android:Theme.Holo.Light">
<item name="selectableItemBackground">?android:attr/selectableItemBackground</item>
...
</style>
次に、ビューにスタイルを使用します:
<TextView
style="@style/LightThemeSelector"
android:text="@string/hello" />
これがお役に立てば幸いです。 ありがとうございました。