Android is not like iOS Searchbar and can only write on its own.
Need a. 9 as a background, EditText as a search box, a delete image, a search image (magnifying glass)
<relativelayout Android:id= "@+id/rlsearchframedelete"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:layout_centervertical= "true"android:gravity= "Center_vertical" > <EditText Android:id= "@+id/etsearch"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_marginright= "10DP"Android:background= "@drawable/search_frame"Android:hint= "Search"Android:paddingleft= "32DP"Android:singleline= "true"android:textsize= "12SP"/> <ImageView Android:id= "@+id/ivdeletetext"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentright= "true"android:layout_centerinparent= "true"Android:paddingright= "20DP"android:src= "@drawable/delete"android:visibility= "Gone"/> </RelativeLayout>
Listen for input box, the Delete button appears.
Etsearch.addtextchangedlistener (NewTextwatcher () { Public voidOnTextChanged (Charsequence S,intStartintbefore,intcount) { //TODO auto-generated Method Stub } Public voidBeforetextchanged (Charsequence S,intStartintCount,intAfter ) { //TODO auto-generated Method Stub } Public voidaftertextchanged (Editable s) {if(s.length () = = 0) {ivdeletetext.setvisibility (view.gone); } Else{ivdeletetext.setvisibility (view.visible); } } });
Delete button click event
Ivdeletetext.setonclicklistener (new Onclicklistener () { publicvoid OnClick (View v) { etsearch.settext (""); } });
Android Development-Imitation iOS searchbar right Delete button