Android 自定義搜索框

1. 準備一個邊框xml

新建xml, 命名 layout_border.xml, 內容如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">

    <solid android:color="#FFFFFF" />

    <stroke
        android:width="0.01dp"
        android:color="#BFBFBF"/>

    <!-- 這個可以不加,padding用不上 -->
    <!--<padding-->
        <!--android:bottom="1dp"-->
        <!--android:left="0.5dp"-->
        <!--android:right="0.5dp"-->
        <!--android:top="0dp" />-->

    <!--圓角-->
    <corners
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp" />

</shape>

2. 自定義搜索框的代碼

    <!-- 背景 -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_margin="20dp"
        android:background="@drawable/layout_border"
        android:orientation="horizontal">

        <!-- 搜索框信息 -->
        <EditText
            android:id="@+id/search_edittext"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginLeft="10dp"
            android:hint="@string/search"
            android:drawableLeft="@drawable/icon_search"
            android:gravity="center_vertical"
            android:imeOptions="actionDone"
            android:inputType="text"
            android:maxLines="1"
            android:textSize="17sp"
            android:theme="@style/MyEditText"
            android:background="@null"/>
    </LinearLayout>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章