0

I'm writing a custom EditText that will have functionalities to bold/italic/underline/lists .... for Android

It's working so far so good but I've a problem that when a user clicking on a Button (for styling bold/italic...), the user will lose focus on the EditText.

Anyone has any ideas how to prevent the button taking focus from the EditText?

Thanks :)

Huy.Vu
  • 173
  • 10

1 Answers1

0

The easiest thing to do would be to have the onClickListener of those buttons refocus the edit text as their last instruction.

You can also try putting focusable=false (and focusableInTouchMode=false) on the buttons. That may work, I'm not sure if focus is removed from the edit text when the screen is touched or when another item receives focus, which is subtly but important difference here. It would also slightly change any drawables on the button that use focused state.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • I tried to call requestFocus on that EditText when the button is clicked but still not able to make it focus again... The weird thing is sometimes it does focus again, sometimes it does not, if I put a debug in the requestFocus(), it will always work. I guess it could be that the main thread is doing something behind the scenes. And while i put the breakpoint, it's pausing the other things – Huy.Vu Dec 22 '21 at 13:25