사용자 지정보기를 만들고 있습니다. 이것은 기본적으로 테두리가있는 사각형 상자입니다. 나는 테두리를 색을 바꾸고 사용자가 클릭 할 때 초점을 맞추기를 원합니다. 직사각형에 포커스가 없으면 테두리를 원래 색으로 되돌리고 싶습니다. 이 배경을 양식 배경으로 사용하고 싶습니다. 안드로이드 문서 및 스택 오버플로 해답을 시도하고이 작업을 수행 할 수 없습니다. 클릭 할 수있게 만들었지 만 그 이상으로 진행할 수는 없습니다.사용자 정의보기를 포커스 할 수있게 만드는 방법은 무엇입니까?
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 >= 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) {
}
}
가능한 중복 ] (https://stackoverflow.com/questions/10406354/custom-view-not - 대응 - to-touch) – Danieboy