转载请注明出处:http://blog.csdn.net/krislight/article

1.定义一个Drawable

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>

2.布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:background="@drawable/rounded_edittext" />
</LinearLayout>

如果要使用多个不同状态下的EditText点击效果

1.定义一个selector

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext_states.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/rounded_focused" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/rounded_focused" />
<item
android:state_enabled="true"
android:drawable="@drawable/rounded_edittext" />
</selector>

2.定义Drawable

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext_focused.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<stroke android:width="2dp" android:color="#FF0000" />
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>

3.布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:background="@drawable/rounded_edittext_states"
android:padding="5dip"/>
</LinearLayout>

带圆角的EditText的更多相关文章

  1. 【控件扩展】带圆角、边框、渐变的panel

    下载地址:  http://files.cnblogs.com/chengulv/custompanel_demo.zip using System; namespace LC.Fun { /// & ...

  2. winform GDI基础(二)画带圆角的矩形框

    private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.SmoothingMode ...

  3. CSS 奇思妙想 | 巧妙的实现带圆角的三角形

    之前在这篇文章中 -- <老生常谈之 CSS 实现三角形>,介绍了 6 种使用 CSS 实现三角形的方式. 但是其中漏掉了一个非常重要的场景,如何使用纯 CSS 实现带圆角的三角形呢?,像 ...

  4. 35.Android之带删除按钮EditText学习

    今天实现Android里自定义带删除功能的EditText,效果如下: 当输入内容时,EditText变为带有一个删除功能按钮的编辑框,如图: 实现代码很简单,直接上代码, 布局文件xml: < ...

  5. Android实现自带横线的EditText

    (一)问题 怎样实现带有横栏的EditText(像记事本的编辑界面那样)? (二)初步思路 1.通过修改EditText背景来实现(系统背景是一个框形图片,内部透明,替换为一个带有横栏的图片即可) 2 ...

  6. 带删除的EditText

    在安卓开发中EditText是比较常用的控件之一,那我们平常看到EditText填写了内容之后右边会出现一个删除的按钮,这样可以方便用户对其中文本清空操作,是非常人性化的,我们可以重写EditText ...

  7. java在线聊天项目 使用SWT快速制作登录窗口,可视化窗口Design 更换窗口默认皮肤(切换Swing自带的几种皮肤如矩形带圆角)

    SWT成功激活后 new一个JDialog 调整到Design视图 默认的视图模式是BorderLayout,无论你怎么拖拽,只能放到东西南北中的位置上 所以,我们把视图模式调整为AbsoluteLa ...

  8. 利用UIBezierPath实现一个带圆角的视图

    - (void)drawRect:(CGRect)rect { // draw a box with rounded corners to fill the view - UIBezierPath * ...

  9. Android圆角矩形的实现

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:Android=&quo ...

随机推荐

  1. Working with BeforeProperties and AfterProperties on SPItemEventReceiver

    As many of you know, event receivers are a great way to hook into various SharePoint events.  These ...

  2. SignalR: The new old thing

    As you can see, this is my first blog posted in cnblog. If you find any mistake, don’t hesitate to t ...

  3. Solr使用初探——Solr的安装环境与配置

    Solr是一个apache名下很好用的开源索引.搜索工具,网上的资料虽多但很杂,笔者花了一天的时间对Solr进行了较为初步的研究,对Solr的基础应用做了一定的总结.文中涉及到的配置方法并不唯一,AP ...

  4. WPF动画之关键帧动画(2)

    XAML代码: <Window x:Class="关键帧动画.MainWindow" xmlns="http://schemas.microsoft.com/win ...

  5. Java的云打印Lodop

        打印某一个网页上的内容我们都经常遇到过,比如网上申请港澳通行证时需要填写申请表,然后把申请表给打印出来.像这样的打印技术是怎么实现?这种打印可以通过一种叫云打印的插件来做,按我的理解云打印的技 ...

  6. java之sleep、wait、yield、join、notify乱解

    ① 这两个方法来自不同的类分别是,sleep来自Thread类,和wait来自Object类. sleep是Thread的静态类方法,谁调用的谁去睡觉,即使在a线程里调用b的sleep方法,实际上还是 ...

  7. 第5章标准I/O库总结

    1 fwide函数试图设置流的定向(流的定向决定了读写单字节还是多字节字符) int fwide(FILE *fp,int mode) 宽定向返回正值,字节定向返回负值,为定向返回0 已定向流不会改变 ...

  8. EIGamal密码体制

    EIGamal密码体制:由EIGamal提出,是一种基于离散对数问题的双钥密码体制,既可用于加密,又可以用于签名. 密钥对生成步骤: 1.取大素数p和g<p(g最好是p的素根) 2.选一整数x& ...

  9. dom三个事件

    1,页面加载后 window.onload=function(){}; 2,页面(关闭)卸载后触发 window.onunload=function(){}; 3,页面关闭前触发 window.onb ...

  10. Android App资源的查找过程分析

    Android资源管理框架实际就是由AssetManager和Resources两个类来实现的.其中,Resources类可以根据ID来查找资源,而AssetManager类根据文件名来查找资源.事实 ...