Reputation: 855
<android.support.v7.widget.SearchView
android:id="@+id/search_view"
app:defaultQueryHint="Search By Company"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/greybg"
android:gravity="center"
android:focusableInTouchMode="true"
app:searchHintIcon="@drawable/ic_search_black"
app:closeIcon="@drawable/ic_search_close_black"
app:iconifiedByDefault="false" />
SearchView
not showing keyboard on single click inside AutoCompleteTextView
, first it gains focus then on clicking again it opens keyboard. What I want is to show keyboard in single click by doing change only in XML code.
Upvotes: 1
Views: 3289
Reputation: 3100
add attr clickable and focusable in EditText like below
<android.support.v7.widget.SearchView
android:id="@+id/search_view"
app:defaultQueryHint="Search By Company"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/greybg"
android:gravity="center"
android:focusableInTouchMode="true"
app:searchHintIcon="@drawable/ic_search_black"
app:closeIcon="@drawable/ic_search_close_black"
app:iconifiedByDefault="false"
android:clickable="true"
android:imeOptions="actionSearch"
android:focusable="true" />
Upvotes: 0
Reputation: 1802
Try this
searchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(view, 0);
}
}
}
});
Upvotes: 1
Reputation: 2893
For that you can implement setOnFocusChangeListener
on your searchView
like shown below:
searchView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0);
}
}
});
Where context is your activity context.
Upvotes: 0
Reputation: 1320
Try this :
searchview.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
}
});
Upvotes: 0