How to adjust button border color programmatically in Android?

I want to have a button in Android with a color for the button frame.

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); 

How to do this programmatically?

+5
source share
1 answer
  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); } }); 

try this, but I'm not 100% sure

+7
source

Source: https://habr.com/ru/post/1237363/


All Articles