これは私の形状xmlです
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/comp_background" android:top="0px" android:right="0px" android:left="-5px">
<shape>
<corners android:bottomRightRadius="100px"
android:topRightRadius="100px"/>
<solid android:color="@color/OptionNotSelected" />
<stroke android:width="5px" android:color="#000000" />
</shape>
左側のストロークが欠落していることに注意してください。
私はこれをプログラム的にしたい。私が試したコードはこれです
int cornerRadius=50;
float[] med_corners=new float[]{cornerRadius,cornerRadius,0,0,0,0,cornerRadius,cornerRadius};
LayerDrawable layers1 = (LayerDrawable)ContextCompat.getDrawable(context,R.drawable.medicine_btn_background);
GradientDrawable shape1= (GradientDrawable)(layers1.findDrawableByLayerId(R.id.med_background));
shape1.setColor(ContextCompat.getColor(context,R.color.OptionNotSelected));
shape1.setStroke(5,ContextCompat.getColor(context,android.R.color.black));
shape1.setCornerRadii(med_corners);
btn_medicine.setBackground(shape1);
btn_medicine.setTextColor(ContextCompat.getColor(context,R.color.OptionSelected));
そして、これは私が得る出力です
ここでは、左の境界線を取得します。私はそれをしたくありません。2 つのボタンを並べて配置しました。これらのボタンをクリックすると、これらのボタンの背景が切り替わります。setBackgroundResource()メソッドを試してみると、角が丸くなりません。上記のコードは、丸みを帯びた角を保持するのに役立ちますが、左の境界線を再作成します。これを達成する方法はありますか....?
どんな助けでも大歓迎です