From 600524d548105aa026c0d1900d503bab34c38ce4 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 26 Jun 2017 15:43:32 -0700 Subject: Add back press helper --- .../main/kotlin/ca/allanwang/kau/searchview/SearchView.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'library/src') diff --git a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt index bfeed52..d7ff634 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt @@ -179,6 +179,7 @@ class SearchView @JvmOverloads constructor( init { View.inflate(context, R.layout.kau_search_view, this) + z = 99f iconNav.setSearchIcon(configs.navIcon) iconClear.setSearchIcon(configs.clearIcon).setOnClickListener { editText.text.clear() @@ -186,6 +187,7 @@ class SearchView @JvmOverloads constructor( tintForeground(configs.foregroundColor) tintBackground(configs.backgroundColor) with(recycler) { + isNestedScrollingEnabled = false layoutManager = LinearLayoutManager(context) addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { @@ -263,6 +265,18 @@ class SearchView @JvmOverloads constructor( }) } + /** + * Handle a back press event + * Returns true if back press is consumed, false otherwise + */ + fun onBackPressed(): Boolean { + if (isOpen && menuItem != null) { + revealClose() + return true + } + return false + } + /** * Tint foreground attributes * This can be done publicly through [configs], which will also save the color -- cgit v1.2.3