title: Android button border dynamically
body: <p>I am having a button, without any text only with background color. In <code>onClick()</code> event of the button I need to set the button border without the <code>xml</code> specification. I tried gradient rectangle shape as background <code>drawable</code> to the button which is not flexible for my layout. </p>
  
  <p>How can I set border with specific color to the button? </p>
  
  <p>Here is my code.</p>
  
  <pre><code>    Button btnBlackColor=new Button(this);
      int mButtonWidth=100;
      btnBlackColor.setWidth(mButtonWidth);
      btnBlackColor.setHeight(mButtonWidth);
      btnBlackColor.setBackgroundColor(Color.BLACK);  
  
      btnBlackColor.setOnClickListener(new OnClickListener()
      {
        public void onClick(View v)
        {
          GradientDrawable btnShape = new GradientDrawable(Orientation.BOTTOM_TOP, new int[]{Color.BLUE,Color.LTGRAY});
          btnShape.setCornerRadius(0);
          btnShape.setSize(mButtonWidth, mButtonWidth);
          btnShape.setBounds(10, 10, mButtonWidth, mButtonWidth);
          ClipDrawable btnClip = new ClipDrawable(btnShape, Gravity.LEFT,ClipDrawable.HORIZONTAL);
  
          btnShape = new GradientDrawable(Orientation.BOTTOM_TOP, new int[]{Color.BLACK, Color.DKGRAY});
          btnShape.setCornerRadius(0); 
          btnShape.setSize(mButtonWidth, mButtonWidth);
          btnShape.setBounds(5, 5, mButtonWidth, mButtonWidth);
  
  
          LayerDrawable btnLayer= new LayerDrawable(new Drawable[]{btnShape, btnClip});
  
          btnBlackColor.setBackgroundDrawable(btnLayer); 
        }
      });
  </code></pre>