Android button - How to set focusable to true and still accept onClick listener on first click?

后端 未结 3 1529
暗喜
暗喜 2021-01-01 23:34

UPDATE

I\'ve solved the clicking issue by removing the two focusable lines from the button style and using the onClick event handler to call r

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 00:14

    you can do like this in onClick(View v):

    .....
    v.setFocusableInTouchMode(true);
    v.requestFocus();
    v.setFocusableInTouchMode(false);
    .....//the others
    

    so, v gets focus and you can do something in onClick() through setFocusableInTouchMode(false), it can accept onClick at first touch.

提交回复
热议问题