6

Android美化EditText

 3 years ago
source link: http://www.androidchina.net/2241.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Android美化EditText – Android开发中文站

目前各种app都讲究用户体验,这里介绍下对EditText控件的样式美化。

先上效果图:

注:第一个控件没有没有设置 background 的任何属性,第二个控件设置了 android:background=”@drawable/bg_edittext_selector”

若希望取消 EditText 背景,直接设置 android:background=”@null” 便可。

此处通过两个xml文件来设置未获得焦点和已经获得焦点的样式,通过shape实现。

edittext_focused.xml

<stroke
android:width="1dip"
android:color="#728ea3" />

edittext_normal.xml

<?xml version="1.0" encoding="UTF-8"?>
<solid android:color="#FFFFFF" />
<corners android:radius="1dip"/>
<stroke
android:width="1dip"
android:color="#BDC7D8" />
</shape>

注:此处可以通过设置 corners   (角) 来设置边框的弧度。想了解shape更多属性可以自行查阅。

bg_edittext_selector.xml

<?xml version="1.0" encoding="UTF-8"?>
<solid android:color="#FFFFFF" />
<corners android:radius="1dip"/>
<stroke
android:width="1dip"
android:color="#BDC7D8" />
</shape>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.aa.MainActivity" >
<EditText
android:id="@+id/normal"
android:layout_width="fill_parent"
android:layout_height="36dip"
android:layout_margin="36dip"
android:hint="请输入用户名"
android:padding="5dip"
android:singleLine="true"
android:textColorHint="#AAAAAA"
android:textSize="15dip" />
<EditText
android:layout_below="@+id/normal"
android:layout_width="fill_parent"
android:layout_height="36dip"
android:layout_margin="36dip"
android:background="@drawable/bg_edittext_selector"
android:hint="请输入用户名"
android:padding="5dip"
android:singleLine="true"
android:textColorHint="#AAAAAA"
android:textSize="15dip" />
</RelativeLayout>

转载请注明:Android开发中文站 » Android美化EditText


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK