Android 經常用的一些屬性

android:inputType=”none”
android:inputType=”text”
android:inputType=”textCapCharacters” 字母大寫
android:inputType=”textCapWords” 首字母大寫
android:inputType=”textCapSentences” 僅第一個字母大寫
android:inputType=”textAutoCorrect” 自動完成
android:inputType=”textAutoComplete” 自動完成
android:inputType=”textMultiLine” 多行輸入
android:inputType=”textImeMultiLine” 輸入法多行(如果支持)
android:inputType=”textNoSuggestions” 不提示
android:inputType=”textUri” 網址
android:inputType=”textEmailAddress” 電子郵件地址
android:inputType=”textEmailSubject” 郵件主題
android:inputType=”textShortMessage” 短訊
android:inputType=”textLongMessage” 長信息
android:inputType=”textPersonName” 人名
android:inputType=”textPostalAddress” 地址
android:inputType=”textPassword” 密碼
android:inputType=”textVisiblePassword” 可見密碼
android:inputType=”textWebEditText” 作爲網頁表單的文本
android:inputType=”textFilter” 文本篩選過濾
android:inputType=”textPhonetic” 拼音輸入
//數值類型
android:inputType=”number” 數字
android:inputType=”numberSigned” 帶符號數字格式
android:inputType=”numberDecimal” 帶小數點的浮點格式
android:inputType=”phone” 撥號鍵盤
android:inputType=”datetime” 時間日期
android:inputType=”date” 日期鍵盤
android:inputType=”time” 時間鍵盤

android:layout_gravity=“center_vertical” 設置控件顯示的位置:默認top,這裏居中顯示,還有bottom 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:textAlign=“center” EditText沒有這個屬性,但TextView有 android:textColorHighlight="#cccccc" 被選中文字的底色,默認爲藍色
android:textColorHint="#ffff00" 設置提示信息文字的顏色,默認爲灰色

android:textScaleX=“1.5” 控制字與字之間的間距
android:typeface=“monospace” 字型,normal, sans, serif, monospace

android:background="@null" 空間背景,這裏沒有,指透明
android:layout_weight=“1” 權重,控制控件之間的地位,在控制控件顯示的大小時蠻有用的。
android:textAppearance="?android:attr/textAppearanceLargeInverse" 文字外觀,這裏引用的是系統自帶的一個外觀,?表示系統是否有這種外觀,否則使用默認的外觀。不知道這樣理解對不對?

通過EditText的layout xml文件中的相關屬性來實現:

  1. 密碼框屬性 android:password=“true” 這條可以讓EditText顯示的內容自動爲星號,輸入時內容會在1秒內變成*字樣。
  2. 純數字 android:numeric=“true” 這條可以讓輸入法自動變爲數字輸入鍵盤,同時僅允許0-9的數字輸入
  3. 僅允許 android:capitalize=“cwj1987” 這樣僅允許接受輸入cwj1987,一般用於密碼驗證 下面是一些擴展的風格屬性
    android:editable=“false” 設置EditText不可編輯
    android:singleLine=“true” 強制輸入的內容在單行
    android:ellipsize=“end” 自動隱藏尾部溢出數據,一般用於文字內容過長一行無法全部顯示時
發佈了18 篇原創文章 · 獲贊 1 · 訪問量 6936
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章