如何确保我的搜索视图加载键盘时不会弹出?

How do I make sure the moment my search view loads keyboard doesnt popup?

我在 xml 中使用编辑文本作为搜索框。我一调用抽屉和键盘弹出窗口就加载搜索框。我想让它除非触摸搜索框,否则键盘不会弹出。我该怎么做? 到目前为止,这是我的代码:

<EditText
                android:id="@+id/search_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/searchbox"
                android:gravity="left|center_vertical"
                android:hint="Search"
                android:textColorHint="@android:color/darker_gray"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:imeOptions="actionSearch"
                android:inputType="textNoSuggestions"
                android:paddingBottom="5dp"
                android:paddingLeft="20dp"
                android:paddingRight="30dp"
                android:paddingTop="5sp"
                android:singleLine="true"
                android:textColor="@android:color/darker_gray"
                android:textSize="20dp" />

对应class:

    EditText inputSearch;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,    Bundle savedInstanceState) {
        inputSearch = (EditText) view.findViewById(R.id.search_text);

}

蚂蚁线索?谢谢!

试试这个,在 onCreate

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)

转到您的应用程序清单文件,并为您想要禁用自动键盘弹出的activity写下这一行。

android:windowSoftInputMode="stateHidden"

唯一的解决办法是确保另一个元素有焦点,或者清除 onResume() 中的焦点。这是关于该主题的类似问题:Stop EditText From Gaining Focus. You can do this by creating another empty element and setting the attributes android:focusable="true" and android:focusableInTouchMode="true" And you can clear the focus simply by calling clearFocus() on your EditText.