개발모음집

setOnFocusChangeListener not working 본문

Android

setOnFocusChangeListener not working

void 2017. 8. 4. 14:20
cameraBtn.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFoous) {
if(hasFoous){
cameraBtn.setBackgroundResource(R.drawable.shape_circle_red);
} else {
cameraBtn.setBackgroundResource(R.drawable.shape_circle);
}
}
});


포커스를 받았을 때 버튼의 모양이 달라지길 원했다.

하지만 setOnFocusChangeListener은 작동하지 않음

원하는 동작을 setOnFocusChangeListener로 하지않고 setOnTouchListener로 구현하니 

cameraBtn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
int action=motionEvent.getAction();

if(action==MotionEvent.ACTION_DOWN){
cameraBtn.setBackgroundResource(R.drawable.shape_circle_red);
} else if(action==MotionEvent.ACTION_UP){
cameraBtn.setBackgroundResource(R.drawable.shape_circle);
}
return false;
}
});


동작됨