0

我使用以下代码创建了一个自定义按钮:

Button goButton = (Button) findViewById(R.id.buttonStartTest);
    View v = findViewById(R.id.buttonStartTest);
    v.setBackground( new DrawableGradient(new int[] { btnColor,btnColor, 0xffffffff }, 110,10));
    goButton.setText(getString(R.string.START_FORM));

DrawableGradent 的样子:

public class DrawableGradient extends GradientDrawable {
    DrawableGradient(int[] colors, int cornerRadius,int strokeSize) {
        super(Orientation.BOTTOM_TOP, colors);

        try {
            this.setShape(GradientDrawable.RECTANGLE);
            this.setGradientType(GradientDrawable.LINEAR_GRADIENT);
            this.setCornerRadius(cornerRadius);
            int strokeColor = Color.argb(50, 0, 0, 0);
            this.setStroke(strokeSize,strokeColor);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

这会产生一个如下所示的按钮: 结果按钮

这就是我想要得到的,只是我希望中风只在按钮的外面。我怎样才能做到这一点?

这就是所需的外观: 想要的样子

谢谢你的帮助!:) /丹尼尔

4

0 回答 0