[Android] SearchView 美化成圆角效果

先来看一下美化了背景后的效果图 

 

bg_searchview.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- 角度 -->
    <corners android:radius="35dp"/>
    <!-- 填充色 -->
    <solid android:color="@color/background_menu"/>
    <!-- 描边 设置线宽及颜色 -->
    <stroke android:color="@color/background_menu" android:width="0.5dp"/>
</shape>

 

SearchView 使用

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.SearchView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/search_view"
        android:theme="?attr/actionBarStyle"
        android:background="@drawable/bg_searchview"
        android:layout_width="match_parent"
        android:layout_height="34dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:imeOptions="actionSearch"
        app:queryBackground="@drawable/bg_searchview"
        app:submitBackground="@color/transparent"
        app:defaultQueryHint="搜索"/>

 

就这样, 不改一行代码就完事了.

 

posted @ 2020-03-17 12:48  我爱我家喵喵  阅读(1812)  评论(0编辑  收藏  举报