0

这是我的形状 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));

这是我得到的输出 在这里我得到了左边框。我不想要那个。我并排放置了两个按钮,当单击这些按钮时,我在这些按钮的背景之间切换。当我尝试setBackgroundResource()方法时,我失去了圆角。我上面给出的代码有助于保留圆角但重新创建左边框。有什么方法可以实现这一点......? 图像2

任何帮助深表感谢

4

0 回答 0