资料来自:菜鸟教程
自行编写一个ShapeDrawable的资源文件!然后TextView将blackgroung 设置为这个drawable资源即可!
shapeDrawable资源文件的几个节点以及属性:
- <solid android:color = "xxx"> 这个是设置背景颜色的
- <stroke android:width = "xdp" android:color="xxx"> 这个是设置边框的粗细,以及边框颜色的
- <padding androidLbottom = "xdp"...> 这个是设置边距的
- <corners android:topLeftRadius="10px"...> 这个是设置圆角的
- <gradient> 这个是设置渐变色的,可选属性有: startColor:起始颜色 endColor:结束颜色 centerColor:中间颜色 angle:方向角度,等于0时,从左到右,然后逆时针方向转,当angle = 90度时从下往上 type:设置渐变的类型
一、自定义输入框列子:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient android:angle="45" />
<!--设置边距-->
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
<!-- 设置圆角矩形 -->
<corners android:radius="3dp" />
<!--设置边框粗细和颜色-->
<stroke
android:width="2px"
android:color="#838B8B" />
<!--<solid android:color="#838B8B" />-->
</shape>
二、在需要使用图文输入时,需要让drawableleft和文字有一个间隔的话:
android:drawablePadding="5dp"
android:drawableLeft="@drawable/phone"
需要改变光标的颜色:
1、自定义bg_cursor的drawable下xml文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:width="1dp" />
<solid android:color="#dbdbdb" />
</shape>
2、在edittext下添加:
android:textCursorDrawable="@drawable/bg_cursor"
三、不自动获取焦点
在edittext的父级容器中添加属性:
android:focusable="true"
android:focusableInTouchMode="true"