android-v7 지원으로 xml에서 selectableItemBackground 적용
내 애플리케이션에 Android 지원 v7이 포함되어 있어도
첨가 android:background="?android:attr/selectableItemBackground"
내 IDE, Eclipse에서 오류 (컴파일 방지)를 발생시켜 selectableItemBackground가 최소 Api 11 이상에만 해당됨을 알립니다.
이 속성을 XML의 배경에 어떻게 추가합니까?
상위 라이브러리에서 복사 및 붙여 넣기가 해결책이 아니라고 가정합니다.
속성이 라이브러리 (v7 지원)에 정의되어 있으므로 사용자 정의 속성으로 사용합니다. 즉, android:
접두사 없이 :
android:background="?attr/selectableItemBackground"
표시되는 오류는 ?android:attr/selectableItemBackground
API 버전> = 11에서 사용할 수 있음을 지적하고 있습니다. 사실입니다.
여기 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>
Android SDK 디렉토리에서 드로어 블을 찾을 수 있습니다.
../platforms/android-14/data
주제에 대한 전문가는 아니지만 플랫폼 버전 기반 테마가 필요한 것 같습니다. 공식 가이드는 꽤 잘 내가 생각하는이 과정을 설명합니다.
각 버전에 대해 서로 다른 XML 파일을 만들고에 저장해야한다 res/values-v7
, res/values-v11
등등 그런 다음 뷰의 그 스타일을 사용합니다. 이 같은:
에서 res/values-v7
:
<style name="LightThemeSelector" parent="android:Theme.Light">
...
</style>
에서 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" />
도움이 되었기를 바랍니다. 건배.
'Programing' 카테고리의 다른 글
jQuery 업로드 진행률 및 AJAX 파일 업로드 (0) | 2020.11.03 |
---|---|
Ruby on Rails : test_unit에서 rspec으로 전환 (0) | 2020.11.03 |
Linux : umount를 수행 할 때 어떤 프로세스가 "장치 사용 중"을 유발합니까? (0) | 2020.11.03 |
알 수없는 너비의 정렬되지 않은 목록을 가로 중앙에 배치하는 방법은 무엇입니까? (0) | 2020.11.03 |
Android WebView를 통해 JavaScript에서 Java 함수 호출 (0) | 2020.11.02 |