自定义EditText样式-(包括光标背景)

效果图:
自定义EditText样式-(包括光标背景)_第1张图片
布局文件中

<EditText  android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/ETEditAlbumInfoText" />

样式:ETEditAlbumInfoText

<style name="ETEditAlbumInfoText">
        <item name="android:textSize">@dimen/subtitle</item>
        <item name="android:textColor">@color/black</item>
        <item name="android:textColorHint">@color/gray</item>
        <item name="android:paddingBottom">@dimen/dp10</item>
        <item name="android:paddingTop">@dimen/dp10</item>
        <item name="android:paddingLeft">@dimen/dp10</item>
        <item name="android:background">@drawable/et_style</item>
        <item name="android:textCursorDrawable">@drawable/et_cus_black_cursor</item>
    </style>

背景background:
et_style

<?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="@color/white" />
            <padding android:bottom="2dp" />
        </shape>
    </item>
    <item android:bottom="10dp">
        <shape android:shape="rectangle" >
            <solid android:color="@color/white" />

            <padding  android:left="2dp" android:right="2dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@color/gray_et_bg" />
        </shape>
    </item>
</layer-list>

对应颜色:

<item name="gray_et_bg"  type="color">#F2F2F2</item>

光标:
et_cus_black_cursor

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size  android:width="@dimen/dp2" />
    <solid  android:color="@color/black" />
    <padding  android:top="@dimen/dp2" android:bottom="@dimen/dp2" />
</shape>

你可能感兴趣的:(style,自定义,EditText)