用SearchView实现圆形搜索框

实现效果
在这里插入图片描述
一.用shape定义一个圆形框

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
 
    <stroke
        android:width="1dp"
        android:color="#5c5050" />
        
    <corners android:radius="20dp" />
</shape>

二.xml布局(v7包下的SearchView)

<android.support.v7.widget.SearchView
        android:id="@+id/serachview"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_margin="10dp"
        android:background="@drawable/yuan"
        app:iconifiedByDefault="false" />

三.java代码

 //显示搜索框控件
  searchView = (SearchView) findViewById(R.id.serachview);
//设置查询提示字符串
  searchView.setQueryHint("请输入搜索内容");
//设置搜索图标是否显示在搜索框内
 searchView.setIconifiedByDefault(false);

猜你喜欢

转载自blog.csdn.net/wzj_8899174/article/details/83866920