码迷,mamicode.com
首页 > 移动开发 > 详细

Android:设置EditText 背景

时间:2017-08-18 17:11:29      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:sha   ott   tom   9.png   edittext   span   state   omr   blog   

1.android:background 属性
指定控件背景

<EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:background="@drawable/editor_selector" />

  

2.drawable 资源文件

配置样式属性

技术分享

 

 editor_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!--常规演示-->
    <item android:drawable="@drawable/shape_edit_normal" />
    <!--得到焦点时的样式-->
    <item android:drawable="@drawable/shape_edit_focus" android:state_focused="true" />
</selector>

  

 shape_edit_normal.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!--背景色-->
    <solid android:color="#ff00ff" />
    <!--边框样式-->
    <stroke android:width="5dp" android:color="#ffaaaaaa"/>
    <!--圆角样式-->
    <corners android:bottomRightRadius="5dp"
        android:bottomLeftRadius="5dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp"/>
   <!--padding 边距样式-->
    <padding android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp"/>
</shape>

  

shape_edit_focus.xml

与shape_edit_normal.xml 差别不大

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!--背景色-->
    <solid android:color="#ff00ff" />
    <stroke android:width="5dp" android:color="#ff0000aa"/>
    <corners android:bottomRightRadius="5dp"
        android:bottomLeftRadius="5dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp"/>
    <padding android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp"/>
</shape>

  

3.效果如下

技术分享

很丑,但是很温柔。

Android:设置EditText 背景

标签:sha   ott   tom   9.png   edittext   span   state   omr   blog   

原文地址:http://www.cnblogs.com/mojo/p/7390257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!