您的位置:首页 > 移动开发 > Android开发

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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息