Android EditText简单自定义边框样式
2017-03-30 16:48
507 查看
1.去掉全部边框 Android:background="@null"。
2.自定义样式:
shape中如果不通过Android:shape来指定形状时,默认是矩形,其中solid代表纯色,corners代表角,radius越大,圆角越大,stroke代表边框线。
首先定义normal和focus两种状态下的style。
xml:edittext_normal
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent"/>
<corners android:radius="5dip"/>
<stroke android:width="1dip" android:color="#BDDCB2"/>
< /shape>
xml:edittext_focus
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<corners android:radius="5dip"/>
<stroke android:width="1dip" android:color="#265e33"/>
< /shape>
xml:edittext_background
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:drawable="@drawable/bg_et_normal"/>
<item android:state_window_focused="true" android:drawable="@drawable/bg_et_focus"></item>
< /selector>
注意光标会显示在边框最开始 因为边框有圆角故光标会高度大于edittext边框 只需设置edittext的paddingleft和paddingright。
2.自定义样式:
shape中如果不通过Android:shape来指定形状时,默认是矩形,其中solid代表纯色,corners代表角,radius越大,圆角越大,stroke代表边框线。
首先定义normal和focus两种状态下的style。
xml:edittext_normal
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent"/>
<corners android:radius="5dip"/>
<stroke android:width="1dip" android:color="#BDDCB2"/>
< /shape>
xml:edittext_focus
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<corners android:radius="5dip"/>
<stroke android:width="1dip" android:color="#265e33"/>
< /shape>
xml:edittext_background
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:drawable="@drawable/bg_et_normal"/>
<item android:state_window_focused="true" android:drawable="@drawable/bg_et_focus"></item>
< /selector>
注意光标会显示在边框最开始 因为边框有圆角故光标会高度大于edittext边框 只需设置edittext的paddingleft和paddingright。
相关文章推荐
- Android EditText简单自定义边框样式
- 自定义绘制android EditText的背景,定义EditText文字的显示样式
- android自定义多功能EditText 边框状态和删除内容
- android 接受消息广播,简单的自定义notification样式弹出
- Android 自定义Notification消息通知样式并实现与Activity简单交互
- Android自定义EditText:你需要一款简单实用的SuperEditText(一键删除&自定义样式)
- android EditText 有边框 透明样式
- android自定义Button样式(清晰简单)
- Android中通知的简单使用和自定义通知样式
- Android自定义Dialog对话框样式出现的边框无法填满问题
- Android简单自定义圆形和水平ProgressBar的样式
- 自定义android EditText样式及使用方式
- 最简单的android自定义进度条样式
- 一只大二狗的Android历程--简单自定义按钮样式(Custom Button Style)
- 自定义android EditText输入框光标样式
- Android简单自定义Dialog样式
- [Android初级]自定义SeekBar样式(简单说明)
- Android: 自定义Tab样式,一种简单的方式。
- android editText 自定义边框
- Android自定义简单spinner样式