package Ġjp . mi h ails ku z mins . s ug oin ih ongo app . features . base . interfaces Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . view . Menu Ċ import Ġandroid . view . Menu Inflater Ċ import Ġandroid . widget . EditText Ċ import Ġandroidx . appcompat . widget . Search View Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġjp . mi h ails ku z mins . s ug oin ih ongo app . R Ċ import Ġjp . mi h ails ku z mins . s ug oin ih ongo app . extensions . android . find Search View Ċ import Ġjp . mi h ails ku z mins . s ug oin ih ongo app . extensions . android . hide Keyboard Ċ import Ġjp . mi h ails ku z mins . s ug oin ih ongo app . extensions . android . show Keyboard Ċ Ċ interface ĠFilter able List Fragment Ġ: ĠSearch View . On Query Text Listener , ĠApp Fragment Ġ{ ĊĊ ĉ val ĠviewModel : ĠFilter able List ViewModel Ċ ĉ var Ġsearch View : ĠSearch View ĊĊ ĉ override Ġfun Ġon Query Text Change ( new Text : ĠString ?): ĠBoolean Ġ{ Ċĉ ĉ new Text ?. let Ġ{ Ċĉĉ ĉ viewModel . search Text Ġ= Ġit Ċĉĉ ĉ return @ on Query Text Change Ġtrue Ċĉ ĉ } ĊĊĉ ĉ return Ġfalse Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Query Text Submit ( query : ĠString ?): ĠBoolean Ġ{ Ċĉ ĉ activity !!. hide Keyboard () ĊĊĉ ĉ return Ġtrue Ċ ĉ } ĊĊ ĉ fun ĠonCreate Options Menu ( menu : ĠMenu , Ġinflater : ĠMenu Inflater ) Ġ{ Ċĉ ĉ in flater . inflate ( R . menu . menu _ search _ list , Ġmenu ) ĊĊĉ ĉ menu . find Search View ( R . id . menu _ search _ list _ menu _ item _ search ) Ċĉĉ ĉ . also Ġ{ Ġsearch View Ġ= Ġit Ġ} Ċĉĉ ĉ . run Ġ{ Ġapply Search View Attributes ( context ) Ġ} Ċ ĉ } Ċ } Ċ Ċ private Ġfun ĠFilter able List Fragment . apply Search View Attributes ( context : ĠContext ) Ġ{ Ċ ĉ with ( search View ) Ġ{ Ċĉ ĉ query Hint Ġ= Ġ"${ context . getString ( R . string . general _ search )} ..." ĊĊĉ ĉ // Ġhack Ġto Ġmake ĠSearch View Ġfocus able Ċĉ ĉ is Icon ified Ġ= Ġtrue Ċĉ ĉ is Icon ified Ġ= Ġfalse ĊĊĉ ĉ setIcon ified ByDefault ( false ) Ġ// Ġdoesn 't Ġdisplay Ġthe Ġclear Ġicon Ġif Ġsearch Ġtext Ġis Ġempty Ċĉ ĉ setOn Query Text Listener ( this @ apply Search View Attributes ) ĊĊĉ ĉ // Ġtake Ġfull Ġwidth Ċĉ ĉ maxWidth Ġ= ĠInt . MAX _ VALUE ĊĊĉ ĉ // Ġquery Ġtext Ġfor Ġscreen Ġrotation Ċĉ ĉ set Query ( viewModel . search Text , Ġfalse ) Ċ ĉ } ĊĊ ĉ search View Ċĉ ĉ . findViewById < EditText >( android x . appcompat . R . id . search _ src _ text ) Ċĉ ĉ . apply Ġ{ Ċĉĉ ĉ setTextColor ( Context Compat . getColor ( context , ĠR . color . color Detail Text Label )) Ċĉĉ ĉ set Hint TextColor ( Context Compat . getColor ( context , ĠR . color . color Search Text Placeholder )) ĊĊĉĉ ĉ request Focus () Ċĉĉ ĉ show Keyboard () Ċĉ ĉ } Ċ }