2015-12-03 7 views
5

私はボタンの境界線のために異なる色でAndroidにボタンを入れたいと思っています。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); 

これをプログラムで行うにはどうすればよいですか?

答えて

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

これを試してみたが、私は100%

わかりません
関連する問題