2

I have implemented selectable text in android via
android:textIsSelectable="true"

What I now need to do is make the menu disappear when there is touch anywhere other than the text/menu/cursors. How do I achieve this?

iknow
  • 8,358
  • 12
  • 41
  • 68
Kapil
  • 165
  • 1
  • 9

1 Answers1

0

Firstly you can follow this link to hide software keyboard/do action after click outside edittext(or any view type you want to achieve Handle outside click

For example

fun setupUI(view: View, action: () -> Unit) {
// Set up touch listener for non-text box views to hide keyboard.
if (view !is EditText && view !is AppCompatEditText) {
    view.setOnTouchListener { _, _ ->
        action.invoke()
        false
    }
}

//If a layout container, iterate over children and seed recursion.
if (view is ViewGroup) {
    for (i in 0 until view.childCount) {
        val innerView: View = view.getChildAt(i)
        setupUI(innerView, action)
    }
}

}

Then in your action clear your rootview focus to dismiss text copy menu: rootView.clearFocus()

Ho Luong
  • 726
  • 8
  • 12