1. 程式人生 > >Android開發智能車載App(1)---android控件及屬性介紹

Android開發智能車載App(1)---android控件及屬性介紹

ica let apc 文本框 tco 內邊距 inpu otto 小數

1.展示文本控件 TextView

屬性名稱                        描述  
android:text               設置顯示文本.  
android:textSize          設置文字大小,推薦度量單位”sp”,如”15sp”  
android:textStyle         設置字形[bold(粗體) 0, italic(斜體) 1, bolditalic(又粗又斜) 2] 可以設置一個或多個,用“|”隔開  
android:gravity         設置文本位置,如設置成“center”,文本將居中顯示。  
android:hint               Text為空時顯示的文字提示信息,可通過textColorHint設置提示信息的顏色。此屬性在EditView中使用,但是這裏也可以用。 

android:height             設置文本區域的高度,支持度量單位:px(像素)/dp/sp/in/mm(毫米)  
android:maxHeight       設置文本區域的最大高度  
android:minHeight       設置文本區域的最小高度  
android:width             設置文本區域的寬度,支持度量單位:px(像素)/dp/sp/in/mm(毫米),與layout_width的區別看這裏。  
android:maxWidth     設置文本區域的最大寬度  
android:minWidth     設置文本區域的最小寬度 

android:textColor      設置文本顏色  
android:textColorHighlight  被選中文字的底色,默認為藍色  
android:textColorHint   設置提示信息文字的顏色,默認為灰色。與hint一起使用。  
android:textColorLink   文字鏈接的顏色. 
  
android:capitalize        設置英文字母大寫類型。 
android:digits              設置允許輸入哪些字符。如“1234567890.+-*/%\n()” 

android:shadowColor 指定文本陰影的顏色,需要與shadowRadius一起使用。效果:    
android:shadowDx    設置陰影橫向坐標開始位置。  
android:shadowDy    設置陰影縱向坐標開始位置。 

android:maxLength   限制顯示的文本長度,超出部分不顯示。  
android:lines   設置文本的行數,設置兩行就顯示兩行,即使第二行沒有數據。  
android:maxLines    設置文本的最大顯示行數,與width或者layout_width結合使用,超出部分自動換行,超出行數將不顯示。  
android:minLines    設置文本的最小行數,與lines類似。  
android:editorExtras    設置文本的額外的輸入數據。在EditView再討論。  
android:ellipsize           設置當文字過長時,該控件該如何顯示。有如下值設置:”start”—–省略號顯示在開頭;”end”——省略號顯示在結尾;”middle”—-省略號顯示在中間;”marquee” ——以跑馬燈的方式顯示(動畫橫向移動)  
  

  2.編輯文本控件 EditText

android:hint="請輸入數字!"//設置顯示在空間上的提示信息
android:numeric="integer"//設置只能輸入整數,如果是小數則是:decimal
android:singleLine="true"//設置單行輸入,一旦設置為true,則文字不會自動換行。
android:password="true"//設置只能輸入密碼
android:textColor = "#ff8c00"//字體顏色
android:textStyle="bold"//字體,bold, italic, bolditalic
android:textSize="20dip"//大小
android:capitalize = "characters"//以大寫字母寫
android:autoText //自動拼寫幫助
android:capitalize //首字母大寫
android:digits //設置只接受某些數字
android:singleLine//是否單行或者多行,回車是離開文本框還是文本框增加新行
android:numeric //只接受數字
android:phoneNumber //輸入電話號碼
android:editable //是否可編輯
//inputType屬性在EditText輸入值時啟動的虛擬鍵盤的風格有著重要的作用 android:inputType="phone" //電話號碼 android:inputType="textCapCharacters" //字母大寫 android:inputType="textCapWords" //首字母大寫 android:inputType="textCapSentences" //僅第一個字母大寫
android:inputType="textUri" //網址 android:inputType="textEmailAddress" //電子郵件地址
android:inputType="textEmailSubject" //郵件主題 android:inputType="textPersonName" //人名 android:inputType="textPostalAddress" //地址 android:inputType="number" //數字 android:inputType="numberSigned" //帶符號數字格式 android:inputType="numberDecimal" //帶小數點的浮點格式 android:inputType="datetime" //時間日期 android:inputType="date" //日期鍵盤 android:inputType="time" //時間鍵盤

  3.按鈕 button

android:layout_width 表示控件寬度, wrap_content, match_parent,以及具體的值; 長度單位為dp;
android:layout_height 表示控件高度, wrap_content,match_parent,以及具體的值; 長度單位為dp;
android: text 在button上要顯示的文字
android:textSize 在button上要顯示的字體大小
android:textColor 在button上要顯示的字體的顏色
android:padding 設置內邊距
android:drawableTop
android:drawableBottom
android:drawableLeft
android:drawableRight 這四個值表示引入圖片,且該圖片與文字排列的規則
android:background 表示button的背景色或者背景圖片 (即可以接圖片,又可以接顏色值)

  4.常用布局屬性

//屬性值為true或false
android:layout_centerHrizontal 水平居中 
android:layout_centerVertical 垂直居中 
android:layout_centerInparent 相對於父元素完全居中 
android:layout_alignParentBottom 貼緊父元素的下邊緣 
android:layout_alignParentLeft 貼緊父元素的左邊緣 
android:layout_alignParentRight 貼緊父元素的右邊緣 
android:layout_alignParentTop 貼緊父元素的上邊緣 
android:layout_alignWithParentIfMissing 如果對應的兄弟元素找不到的話就以父元素做參照物
//屬性值必須為id的引用名“@id/id-name”
android:layout_below 在某元素的下方 
android:layout_above 在某元素的的上方 
android:layout_toLeftOf 在某元素的左邊 
android:layout_toRightOf 在某元素的右邊 
android:layout_alignTop 本元素的上邊緣和某元素的的上邊緣對齊 
android:layout_alignLeft 本元素的左邊緣和某元素的的左邊緣對齊 
android:layout_alignBottom 本元素的下邊緣和某元素的的下邊緣對齊 
android:layout_alignRight 本元素的右邊緣和某元素的的右邊緣對齊
//屬性值為具體的像素值,如30dip,40px
android:layout_marginBottom 離某元素底邊緣的距離 
android:layout_marginLeft 離某元素左邊緣的距離 
android:layout_marginRight 離某元素右邊緣的距離 
android:layout_marginTop 離某元素上邊緣的距離

  

Android開發智能車載App(1)---android控件及屬性介紹