单击之前的SearchView查询提示 [英] SearchView query hint before clicking it
本文介绍了单击之前的SearchView查询提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个搜索视图,并且有一个查询提示属性.但是,只有在单击搜索视图后,提示才会出现.有没有办法让它在被点击之前出现?
I have a search view and I have a query hint attribute. However the hint appears only after clicking on the search view. Is there a way to make it appear before it has been clicked?
<SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView4"
android:layout_marginBottom="14dp"
android:layout_marginTop="30dp"
android:queryHint="Search" />
我看到了另一个带有类似查询的SO问题,但是并没有解决.这就是为什么我再次询问.
I have seen another SO question with a similar query, but it wasn't solved. That's why I am asking again.
推荐答案
您可以在下面的行中添加以下内容:
You can add these below lines:
SearchView searchView = (SearchView) findViewById(R.id.searchView);
searchView.onActionViewExpanded();
searchView.setIconified(true);
并将其添加到隐藏焦点(键盘)
and add this to hiding focus (Keyboard)
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
search.clearFocus();
}
}, 300);
这篇关于单击之前的SearchView查询提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文