B 站的首页圆形搜索框是比较常见的搜索框,如下图:
其实实现起来非常的简单,一个selector 就能搞定:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="/apk/res/android"><item><shape xmlns:android="/apk/res/android" android:shape="rectangle"><solid android:color="#F2F3F5" /><corners android:radius="20dp" /></shape></item></selector>
布局引入:
<TextViewandroid:orientation="horizontal"android:layout_width="match_parent"android:background="@drawable/search_top_round"android:drawableLeft="@drawable/sousuo"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_marginTop="20dp"android:paddingLeft="10dp"android:layout_height="35dp"></TextView>
效果图: