資料來自:菜鳥教程
自行編寫一個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"