我的活动中有一个不属于工具栏的searchview小部件。在我的onCreate方法中,我使用了 searchView.setIconified(false); ,这确实使searchView成为焦点,但它不会提起键盘,除非我再次单击它。我如何让他们的键盘弹出?在Android中启动活动时不会以编程方式弹出Searchview键盘
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:background="@color/lighterGrey">
<android.support.v7.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:transitionName="@string/search_transition"
android:background="@drawable/search_shape"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/acronym_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
的java:
searchView = (SearchView) findViewById(R.id.search_view);
searchView.setIconified(false);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
View view = this.getCurrentFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(view, 0);
}
这并没有为我工作 – DessertsAndStuff
[您是否尝试过编程显示键盘?](https://开头计算器.com/questions/1109022/close-hide-the-android-soft-keyboard?rq = 1)如果这不起作用,请发布代码和XML,以便我们可以帮助您解决问题 –
是的,我也试过,没有工作 – DessertsAndStuff