Android EditText简单自定义边框样式

来源:互联网 发布:大数据课程培训 编辑:程序博客网 时间:2024/05/18 22:42

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。

0 0