Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

android - Kotlin how remove focus from item in Actionbar menu?

I can't remove focus from item, which is like searchView in my Toolbar. XMl code looks like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.home.activities.TransactionSearchActivity">

<item
    android:id="@+id/action_search"
    android:icon="@drawable/ic_baseline_search_24"
    android:title="Search"
    android:focusable="true"
    android:focusableInTouchMode="true"
    app:actionViewClass="androidx.appcompat.widget.SearchView"
    app:showAsAction="always|collapseActionView" />
  
</menu>

And in code in Fragment like this:

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
    inflater.inflate(R.menu.search_menu, menu)    

    val searchItem: MenuItem = menu.findItem(R.id.action_search)
    val searchView = searchItem.actionView as SearchView

    searchItem.expandActionView()

    if (actualQuery.isNullOrEmpty()){
        searchView.queryHint = "Search"
    } else {
        searchView.setQuery(actualQuery, false)
    }

   searchView.clearFocus() 

clearFocus remove focus, but when I come back to search Fragment, then Is a little bling with keyboard and I see keyboard flashed for a second . How repair this?

question from:https://stackoverflow.com/questions/65940067/kotlin-how-remove-focus-from-item-in-actionbar-menu

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...