<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
在AutoCompleteTextView
内单击时未显示键盘,首先获得焦点然后再次点击它会打开键盘。我想要的是通过仅在XML代码中进行更改来单击显示键盘。
答案 0 :(得分:0)
试试这个:
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);
}
}
});
答案 1 :(得分:0)
为此,您可以在setOnFocusChangeListener
上实施searchView
,如下所示:
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);
}
}
});
上下文是您的活动背景。
答案 2 :(得分:0)
试试这个
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);
}
}
}
});
答案 3 :(得分:0)
在EditText中添加attr clickable和focusable,如下所示
<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" />