默认显示android SearchView EditText

use*_*402 6 android android-layout searchview

我在 android 中使用 SearchView。当我第一次登陆页面时,所有可见的是搜索图标。然后当我单击该图标时,就会出现 EditText。如何让 EditText 从一开始就可见?这是我的 xml:

<SearchView
        android:id="@+id/search"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:queryHint="@string/search_hint"
        android:textSize="16sp" />
Run Code Online (Sandbox Code Playgroud)

poz*_*log 3

编辑 - -

哦对不起!我以为你想做一个“空”查询。我认为您可以使用以下方式以编程方式打开 SearchView:

searchView.setIconified(false);
Run Code Online (Sandbox Code Playgroud)

旧答案--

在 Activity 中您可以尝试:

onSearchRequested();
Run Code Online (Sandbox Code Playgroud)

在 Fragment 中,您可以尝试:

getActivity().onSearchRequested();
Run Code Online (Sandbox Code Playgroud)

祝你好运!