1.去掉边框

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:
     style="?android:attr/textViewStyle"
     android:background="@null" android:textColor="@null"/>


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即可避免,这里就不这么做了),代码如下:

 

[html]  view plain copy
  1. <EditText   
  2.     android:layout_width="fill_parent"  
  3.         android:layout_height="36dip"  
  4.         android:background="@drawable/bg_edittext"  
  5.         android:padding="5dip"  
  6.     android:layout_margin="36dip"  
  7.     android:textColorHint="#AAAAAA"  
  8.     android:textSize="15dip"  
  9.     android:singleLine="true"  
  10.     android:hint="请输入..."  
  11. />  


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

bg_edittext_normal.xml(未获得焦点时)

[html]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">   
  3.     <solid android:color="#FFFFFF" />   
  4.     <corners android:radius="3dip"/>  
  5.     <stroke    
  6.         android:width="1dip"    
  7.         android:color="#BDC7D8" />   
  8. shape>  

bg_edittext_focused.xml(获得焦点时)

[html]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">   
  3.     <solid android:color="#FFFFFF" />   
  4.     <corners android:radius="3dip"/>  
  5.     <stroke    
  6.         android:width="1dip"    
  7.         android:color="#728ea3" />   
  8. shape>  

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

[html]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  3.         <item android:state_window_focused="false" android:drawable="@drawable/contact_edit_edittext_normal" />  
  4.        <item android:state_focused="true" android:drawable="@drawable/contact_edit_edittext_focused" />  
  5. selector>  


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

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



更多相关文章

  1. android edittext 去边框
  2. 改变Android 对话框位置及边框
  3. Android 多行跑马灯 解决焦点抢占
  4. Android EditText自动获取焦点并弹出软键盘,解决EditText在获取
  5. 【Android】如何让跑马灯跑起来-控件请求焦点
  6. Android中设计具有背景图的按钮—ImageButton的焦点及事件处理
  7. 给TextView添加边框
  8. android gridview按钮边框和定制点击颜色

随机推荐

  1. Android通过Service编程实现短信监听,通过
  2. Android(安卓)ORM框架 LiteOrm使用
  3. android IBeacon 开发(一)搜索IBeacon基站
  4. android map (地图)
  5. 在Linux中连接android设备
  6. Android(安卓)应用程序之间内容分享详解(
  7. android 获得Android设备唯一标识码 ANDR
  8. Android中的事件分发机制
  9. Android 开发手记之NDK 编程实例
  10. Android 1.5和Android 2.1在相对布局(Rela