1。防止EditText在底部时弹出输入法将标题给顶上去,可以在清单文件的activity上添加属性:
android:windowSoftInputMode="adjustResize|stateHidden"
2。EditText改变光标颜色,在EditText的布局属性中添加:
Android:textCursorDrawable="@null"
android:textCursorDrawable 这个属性是用来控制光标颜色的,
"@null" 是作用是让光标颜色和text color一样
3。EditText改变底部获取焦点和没获取焦点时的颜色。
第一步:在drawable文件夹下建立line_et_normal.xml和line_et_focus.xml两个资源文件,代码如下:
line_et_normal.xml
[html] view plain copy
- <?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="@android:color/transparent" />
- </shape>
- </item>
- <item
- android:left="-2dip"
- android:right="-2dip"
- android:top="-2dip">
- <shape>
- <solid android:color="@android:color/transparent" />
- <stroke
- android:width="1dip"
- android:color="@color/gray_b4"
- android:dashGap="0dp"
- android:dashWidth="0dip" />
- </shape>
- </item>
- </layer-list>
line_et_focus.xml
[html] view plain copy
- <?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="@android:color/transparent" />
- </shape>
- </item>
- <item
- android:left="-2dip"
- android:right="-2dip"
- android:top="-2dip">
- <shape>
- <solid android:color="@android:color/transparent" />
- <stroke
- android:width="1dip"
- android:color="@color/blue"
- android:dashGap="0dp"
- android:dashWidth="0dip" />
- </shape>
- </item>
- </layer-list>
第二步:建立EditText背景文件line_et_bg.xml,代码如下:
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item
- android:state_focused="true" android:drawable="@drawable/line_et_focuse"/>
- <item android:drawable="@drawable/line_et_normal"/>
- </selector>
第三步:在布局文件中引用,代码如下:
[java] view plain copy
- <EditText
- android:id="@+id/login_account"
- style="@style/login_et"
- android:background="@drawable/line_et_bg"
- android:layout_toRightOf="@+id/login_accounttv"
- android:hint="请输入帐号"/>
现在就可以在EditText获得焦点时,底部的线变成蓝色,失去焦点时变成灰色。