SearchView setIconified(false)自动调用searchview的焦点。我怎么能禁用它?

问题描述 投票:4回答:5

我有以下代码:

  if(mSearchView != null){
        mSearchView.setIconifiedByDefault(false);
        mSearchView.setIconified(false);
        mSearchView.setOnQueryTextListener(this);
        int searchPlateId = mSearchView.getContext().getResources()
                .getIdentifier("android:id/search_plate", null, null);
        View searchPlateView = mSearchView.findViewById(searchPlateId);
        if (searchPlateView != null) {
            searchPlateView.setBackgroundColor(getResources().getColor(R.color.white));
        }
    }

问题是,当我在serachview上设置setIconified(false)时,键盘会弹出,我不希望这种情况发生。有可能以某种方式阻止这种情况吗? PS:我在清单中有这个:

 android:windowSoftInputMode="adjustNothing|stateHidden"

也可以在onCreate中以编程方式进行,但没有运气

android keyboard android-softkeyboard searchview soft-keyboard
5个回答
8
投票

试试这个:

searchView.setFocusable(false);
searchView.setIconified(false);
searchView.clearFocus();

1
投票

我也有同样的问题。我花了很多时间来解决这个问题,最后我创建了一个虚拟的EditText,它隐藏在xml中并请求焦点用于java代码中的编辑文本

    mSearchView.setFocusable(false);
    mSearchView.setIconified(false);
    mSearchView.clearFocus();
    EditText editText = (EditText) findViewById(R.id.dummy);
    editText.requestFocus();

希望它对某人有帮助


0
投票

我使用了edittext,并自己制作了搜索图标和关闭图标的功能。这样,我就不必将“setIconifiedByDefault”设置为edittext。它解决了我的所有问题


0
投票
    searchView.setFocusable(false);
    searchView.setIconified(false);
    searchView.clearFocus();

0
投票

以编程方式删除所有字段,如

searchView.setFocusable(false);
searchView.setIconified(false);
searchView.clearFocus();

并为搜索视图设置xml属性:

<!-- Dummy item to prevent Search view from receiving focus -->

    <LinearLayout
        android:focusable="true" 
        android:focusableInTouchMode="true"
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"/>

<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->

    <android.support.v7.widget.SearchView android:id="@+id/serach_view"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:nextFocusUp="@id/serach_view" 
        android:nextFocusLeft="@id/serach_view"/>

它会工作。

查看此链接以获取参考enter link description here

© www.soinside.com 2019 - 2024. All rights reserved.