res/drawable/my_background.xml에 drawable이 정의되어 있습니다.xml StateListDrawable을 Java에서 수정하십시오.
my_background.xml은 다음과 같습니다
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list >
<item android:drawable="@drawable/product_background_1" />
<item>
<rotate
android:fromDegrees="180"
android:toDegrees="180"
android:pivotX="50%"
android:pivotY="50%"
android:drawable="@drawable/product_background_2"
android:id="@+id/need_to_change_this_color_from_java" />
</item>
<item><color android:color="#4400aa00"/></item>
</layer-list>
</item>
<item>
<layer-list >
<item android:drawable="@drawable/product_background_1" />
<item android:drawable="@drawable/product_background_2" />
</layer-list>
</item>
</selector>
나는 다음 뷰 당김으로 my_background 설정하고 잘 작동합니다.
하지만 내 선택기의 layerList에 저장된 자바 요소의 값을 자바 코드에서 변경해야합니다. 어떻게해야합니까?
내 뷰에서 getBackground()를 호출 한 다음 StateListDrawable을 가져올 수 있지만 StateListDrawable에서 드로어 블 자식을 가져 오는 메서드를 찾을 수 없습니다.
감사합니다. 완벽하게 작동합니다. – MTilsted