本文实例讲述了Android EditText自定义样式的方法。分享给大家供大家参考,具体如下:

1.去掉边框

EditText的background属性设置为@null就搞定了:android:background="@null"
style属性倒是可加可不加

附原文:

@SlumberMachine, that's a great observation! But, it seems that there is more to making a TextView editable than just setting android:editable="true". It has to do with the "input method" - what ever that is - and that is where the real difference between TextView and EditText lies. TextView was designed with an EditText in mind, that's for sure. One would have to look at the EditText source code and probably EditText style to see what's really going on there. Documentation is simply not enough.

I have asked the same question back at android-developers group, and got a satisfactory answer. This is what you have to do:

XML:

Instead of style="?android:attr/textViewStyle" you can also write style="@android:style/Widget.TextView", don't ask me why and what it means.

2.Android EditText 改变边框颜色

第一步:为了更好的比较,准备两个一模一样的EditText(当Activity启动时,焦点会在第一个EditText上,如果你不希望这样只需要写一个高度和宽带为0的EditText即可避免,这里就不这么做了),代码如下:

接下来建立三个xml文件,分别为输入框未获得焦点时的背景,输入框获得焦点时的背景,selector背景选择器(这里能获得输入框什么时候获得和失去焦点),代码如下:

bg_edittext_normal.xml(未获得焦点时)

<?xml version="1.0" encoding="UTF-8"?>      

bg_edittext_focused.xml(获得焦点时)

<?xml version="1.0" encoding="UTF-8"?>      

bg_edittext.xml(selector选择器,这方面资料网上很多)

<?xml version="1.0" encoding="UTF-8"?>        

这样就OK了,效果图如下:

第二个输入框边框变为深色,是不是这样更友好点。

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android通信方式总结》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。

更多相关文章

  1. 移动端border-radius的几个BUG
  2. android 文本增大时背景的改变
  3. 如何实现Android(安卓)布局背景模糊化处理
  4. android listview item 被选中背景色设置
  5. android 布局背景模糊化处理
  6. android EditText文本改变监听和获取到焦点的监听(欢迎留言)
  7. android ellipsize的使用及实现跑马灯效果总结
  8. android开发之定制标题栏 --- 附源码
  9. 【转】android ListView几个比较特别的属性

随机推荐

  1. mix
  2. fill_parent和wrap_content 区别和使用效
  3. android数据存储之File
  4. android开关飞行模式的方法
  5. 一个项目搞明白Android(安卓)启动模式和t
  6. android 中apk如何防止反编译?
  7. Android(安卓)API——自定义组件(Custom C
  8. android API key 如何获取
  9. 详解Android获取系统内核版本的方法与实
  10. Android源码在线阅读