2つのドローアブルアイテムを配置する方法、1つはクリックして他の状態を表示 クリックされていない状態!! コードJavaで!! 私のプログラムでは、動的に新しいビューを作成し、そのうちのどれがデフォルト状態で異なる色を持っているか (android:state_pressed="false" の場合) のためです。
これとまったく同じですが、Javaコードでは:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- PRESSED -->
<item android:state_pressed="true">
<shape android:shape="rectangle">
<stroke android:color="#286DCC" android:width="2dp"/>
<corners android:bottomLeftRadius="5dp" android:bottomRightRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" />
<!-- Gradient Bg for listrow -->
<gradient android:startColor="#f1f1f2" android:centerColor="#e7e7e8"
android:endColor="#cfcfcf" android:angle="270" />
</shape>
</item>
<!-- DEFAULT -->
<item >
<shape android:shape="rectangle" >
<corners android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp" />
<!-- Gradient Bg for listrow -->
<gradient **android:startColor="#F75522" android:centerColor="#F75522"**
**android:endColor="#F75522"** android:angle="270" />
</shape>
</item>
</selector>
私はそれを次のように変更しようとしました:
Drawable shape = getResources(). getDrawable(R.drawable.bg_defaults);
android:startColor
動的に変更するcenterColor
方法がわかりません。endColor
すべてのために考えます。