单击它之前的 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.
推荐答案
您可以添加以下几行:
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屋!
查看全文