2
사용자 drawable xml 안에 attr을 넣으려고 할 때 문제가 있습니다. 여기 맞춤형 드로어 블에 attr을 넣는 방법은 무엇입니까?
내 레이아웃 샘플입니다 : <Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_custom_btn"/>
그런 다음 내 사용자 지정 당김 "my_custom_btn"나는 attr_my_custom_color와 색상을 지정하려면 :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="?attr/attr_my_custom_color" /> <!-- pressed -->
</selector>
내 attr.xml 파일 :
<resources>
<attr name="attr_my_custom_color" format="color"/>
</resources>
내 style.xml 파일 인 my appli 내 레이아웃을 테스트 할 때
<resources>
<style name="AppThemeTest" parent="Theme.AppCompat.Light.NoActionBar">
<item name="attr_my_custom_color">@color/primary</item>
</style>
내 ATTR 잘 작동,하지만 난 내 사용자 지정 당김 안에 넣어 때, 그것은 작동하지 않습니다 양이온 (내 매니페스트)이 테마를 사용하고 있습니다.
그것은 잘 컴파일,하지만 난 내 응용 프로그램을 실행하면,이 오류가 표시 org.xmlpull.v1.XmlPullParserException : 바이너리 XML 파일 라인 # 4 :
에 의한 태그는 '당김'을 요구를 속성 또는 하위 태그 드로어 블을 정의하는 방법
맞춤형 드로어 블에 attr을 지정할 수 있습니까?
그것은 더 이상 충돌하지 않습니다, 그러나 그것은'적용되지 않습니다 <항목 안드로이드 : state_pressed = "true"로 안드로이드 : 당김 = "ATTR/attr_my_custom_color을"/> '중. – curiousStranger123
minSdkVersion은 무엇입니까? –
minSdkVersion 16 – curiousStranger123