線形レイアウトの背景としてドローアブルリソースを設定する小さなAndroidアプリケーションを開発しています。次に、線形レイアウトの背景色を動的に変更しますが、描画可能なリソース内で変更します。私のコードは次のようになります:
// bcd.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:endColor="#22000000"
android:startColor="#22000000"
android:angle="270" />
<stroke
android:width="3dp"
android:color="@color/white" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<LinearLayout
android:id="@+id/lin_llt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
そして、私はこのような私の活動で線形レイアウトの背景を設定しました...
parentLayout = (LinearLayout) view.findViewById(R.id.lin_llt);
parentLayout.setBackgroundResource(R.drawable.bcd);
今、私がやりたいことは、ドローアブルリソースの色を変更したいということです。つまり、ドローアブルで定義された丸い角とパディングを使用して、線形レイアウトの色を変更します。
私はこれを次のように試しました
ShapeDrawable bgShape = (ShapeDrawable )parentLayout.getBackground();
bgShape.getPaint().setColor(Color.BLACK);
しかし、それは私にとってはうまくいきません。その他の解決策。
だからそれを行う方法...助けが必要です...ありがとう...