hhl*_*hhl 6 android border button
我想在Android中有一个按钮边框颜色不同的按钮.
Button Bt = new Button(this);
Bt.setId(i+1);
Bt.setBackgroundColor(getResources().getColor(R.color.white)) ;
Bt.setText(restList.get(i));
Bt.setLayoutParams(params3);
Bt.setTextColor(Color.parseColor("gray"));
layout.addView(Bt);
Run Code Online (Sandbox Code Playgroud)
我该如何以编程方式执行此操作?
Tan*_*ano 10
yourButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShapeDrawable shapedrawable = new ShapeDrawable();
shapedrawable.setShape(new RectShape());
shapedrawable.getPaint().setColor(Color.RED);
shapedrawable.getPaint().setStrokeWidth(10f);
shapedrawable.getPaint().setStyle(Style.STROKE);
yourButton.setBackground(shapedrawable);
}
});
Run Code Online (Sandbox Code Playgroud)
试试这个,但我不确定100%
| 归档时间: |
|
| 查看次数: |
5914 次 |
| 最近记录: |