title: How to make your custom view focusable?
body: <p>I am creating a custom view. This is basically a rectangle box with borders in it. I want the border to change color and make it focusable when a user clicks on it. I want the border to return to original color if the rectangle loses focus. I want to use this background as form background. I have tried android documentation and stack overflow answers and I am not able to do this. I have made it clickable but I am not able to proceed further than that.</p>
  
  <pre><code>public class FormBackgroundView extends View implements View.OnClickListener{
  
      private int _borderColor;
      Paint fillPaint, strokePaint;
      Canvas canvas;
  
      public FormBackgroundView(Context context) {
          super(context);
          init();
      }
  
      public FormBackgroundView(Context context, @Nullable AttributeSet attrs) {
          super(context, attrs);
          init();
      }
  
      public FormBackgroundView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
          init();
      }
  
      public FormBackgroundView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
          super(context, attrs, defStyleAttr, defStyleRes);
          init();
      }
  
      private void init(){
          super.setOnClickListener(this);
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          super.onDraw(canvas);
  
          fillPaint = new Paint();
          strokePaint = new Paint();
  
          fillPaint.setStyle(Paint.Style.FILL);
          fillPaint.setColor(Color.WHITE);
  
          strokePaint.setStyle(Paint.Style.FILL);
          strokePaint.setColor(Color.BLACK);
          strokePaint.setAntiAlias(true);
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP){
              canvas.drawRoundRect(0,0,getWidth(),getHeight(), 10, 10, strokePaint);
              canvas.drawRoundRect(0 + 3,0 + 3,getWidth() - 3,getHeight() - 3, 7, 7, fillPaint);
          } else {
              canvas.drawRect(0,0,getWidth(),getHeight(), strokePaint);
              canvas.drawRect(0 + 4,0 + 4,getWidth() -4 ,getHeight() -4, fillPaint);
          }
  
          this.canvas = canvas;
      }
  
  
  
      @Override
      public void onClick(View view) {
  
      }
  
  
  }
  </code></pre>