Android - Make whole search bar clickable
Answers
Answers
I am using a search-view element in my fragment to implement search feature.
<SearchView
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginBottom="7dp"
android:background="@color/white" />

The problem is only the search icon is clickable other area in the search bar is not clickable, when i click the icon only i can able to search.

Can you please help me to make the whole search area clickable.

Answers
What is the clickable mean? trigger search action or just make the edit area focused? If it is the first, you can just make the icon clickable=false. and make the whole layout clickable and implement a event listener.
<SearchView
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:click="onClick"
android:layout_marginTop="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginBottom="7dp"
android:background="@color/white" />
The onClick method should be
public void onClick(View v) {
InputMethodManager im = ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE));
im.showSoftInput(editText, 0);
}
Answers
add this to your xml android:iconifiedByDefault="false" it will keep
open your searchview.
and to clear it add clearfocus to your searchview object.
コメント