[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="搜索"/>

 

就這樣, 不改一行代碼就完事了.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM