android開發之仿微信輸入框效果

  • 仿微信輸入框效果圖:
    這裏寫圖片描述

  • 輸入框:

<EditText
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_marginLeft="50dp"
     android:layout_marginRight="50dp"
     android:background="@drawable/weixin_edittext"
     android:layout_alignParentBottom="true"
     android:layout_marginBottom="6dp"
     android:paddingLeft="5dp"
     android:paddingRight="30dp"
     android:textColor="#000000"/>
  • background:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <solid android:color="#0ac39e" />
        </shape>
    </item>

    <item android:bottom="6dp">
        <shape android:shape="rectangle" >
            <solid android:color="#ffffff" />
        </shape>
    </item>

    <item
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp">
        <shape android:shape="rectangle" >
            <solid android:color="#ffffff" />
        </shape>
    </item>

</layer-list> 
  • 思路:
    採用LayerList來實現,分三層實現,這裏假設activity的背景是白色,第一層也(就是最底層)是綠色;第二次是白色,但是距離底部有一段小偏移,目的是爲了做出文本框兩邊的小勾;第三層也是白色,但是它距離底部和左右兩邊都有一定距離。通過三層配合,即可實現這種效果。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章