SearchView自定义搜索框及使用

xml使用v7控件

    <android.support.v7.widget.SearchView
            android:id="@+id/search"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@drawable/shape"/>

如果我们想让使用美观,那么需要自定义属性shape

自定义属性shape

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#e1dcdc" />
    <stroke
        android:width="1dp"
        android:color="#181616" />
    <corners
        android:bottomLeftRadius="45dp"
        android:bottomRightRadius="45dp"
        android:radius="50dp"
        android:topLeftRadius="45dp"
        android:topRightRadius="45dp" />
</shape>

最重要的就是我们的使用啦,话不多说上代码~

search使用

onQueryTextSubmit 输入完点击后进行搜索

onQueryTextChange输入改变后进行搜索

search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String s) {

                return false;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                goodsPresenter.goodsShow(page, s);
                return false;
            }
        });

猜你喜欢

转载自blog.csdn.net/LG_lxb/article/details/85546277