此步骤是为了复用这个样式, 也可以不用style, 直接在 layout里的布局 xml 里 写代码
<!-- drawable/values/styles.xml --> <style name="SmsEditText"> <item name="android:layout_marginLeft">20dp</item> <item name="android:layout_marginRight">20dp</item> <item name="android:layout_marginTop">20dp</item> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textSize">16sp</item> <item name="android:background">@drawable/edittext_shape</item> </style>
在layout的布局文件中引用定制的edittext
<!-- drawable/layout/fragment_bomb.xml --> <LinearLayout android:id="@+id/input" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="20dp" > <EditText android:id="@+id/phone" style="@style/SmsEditText" android:hint="@string/phone_hint" android:inputType="phone" android:maxLength="11" android:maxLines="1" /> <EditText android:id="@+id/times" style="@style/SmsEditText" android:hint="@string/times_hint" android:inputType="number" android:maxLines="1" /> </LinearLayout>
在edittext 底部加上一条直线( 仿微信)
原生的效果是edittext底部是一个凹形的线,这样不是很美观。微信的输入框下面是一条直线。如何实现呢?可以将上面的图片改成直线型的,不过需要美工人员 PS 的帮忙。我们也可以利用 xml 文件来画出图形,完成所需的直线效果。

利用xml 画线
本来想利用xml 画线, 做出微信 输入框 的那种下面是一条直线,发现纯粹用xml不美观, 这种还是让美工做一个背景图可能比较好。










