TextView 是用于顯示字符串的組件,對于用戶來說就是屏幕中一塊用于顯示文本的區(qū)域。
TextView 類的層次關系如下:
java.lang.Object
? android.view.View
? android.widget.TextView
直接子類:
Button,
CheckedTextView,
Chronometer,
DigitalClock,
EditText
間接子類:
AutoCompleteTextView,
CheckBox,
CompoundButton,
ExtractEditText,
MultiAutoCompleteTextView,
RadioButton,
ToggleButton
TextView 類方法
前面是方法,中間解釋,后面為方法的返回值
getDefaultMovementmethod //獲取默認的箭頭按鍵移動方式 //Movementmethod
getText //獲得TextView 對象的文本 //CharSquence
length //獲得TextView 中的文本長度 //Int
getEditableText //取得文本的可編輯對象,通過 這個對象可對TextView 的文本進行操作,如在光標之后插入字符 //Void
getCompoundPaddingBottom //返回底部填充物 //Int
setCompoundDrawables //設置圖像顯示的位置,在 設置該Drawable 資源之前需要調用setBounds(Rect) //Void
setCompoundDrawablesWithIntrinsicBounds //設置Drawable 圖像的顯示位置,但其邊界不變 //Void
setPadding //根據(jù)位置設置填充物 //Void
getAutoLinkMask //返回自動連接的掩碼 //Void
setTextColor //設置文本顯示的顏色 //Void
setHighlightColor //設置文本選中時顯示的顏色 //Void
setShadowLayer //設置文本顯示的陰影顏色 //Void
setHintTextColor //設置提示文字的顏色 //Void
setLinkTextColor //設置鏈接文字的顏色 //Void
setGravity //設置當TextView 超出了文本本身時橫向以及垂直對齊 //Void
getFreezesText //設置該視圖是否包含整個文本,如果包含則返回真值,否則返回假值 //Boolean
屬性
android:autoLink //設置是否當文本為URL 鏈接/email/電話號碼/map 時,文本顯示為可點擊的鏈接??蛇x值(none/web/email/phone/map/all)
android:autoText //如果設置,將自動執(zhí)行輸入值的拼寫糾正。此處無效果,在顯示輸入法并輸入的時候起作用。
android:bufferType //指定getText()方式取得的文本類別。選項editable 類似于StringBuilder 可追加字符,也就是說getText 后可調用append 方法設置文本內容。
android:capitalize //設置英文字母大寫類型。此處無效果,需要彈出輸入法才能看得到,參見EditView 此屬性說明。
android:cursorVisible //設定光標為顯示/隱藏,默認顯示。
android:digits //設置允許輸入哪些字符。如“1234567890.+-*/%\n()”
android:drawableBottom //在text 的下方輸出一個drawable,如圖片。如果指定一個顏色的話會把text 的背景設為該顏色,并且同時和background 使用時覆蓋后者。
android:drawableLeft //在text 的左邊輸出一個drawable,如圖片。
android:drawablePadding //設置text 與drawable(圖片)的間隔,與drawableLeft、drawableRight、drawableTop、drawableBottom 一起使用,可設置為負數(shù),單獨使用沒有效果。
android:drawableRight //在text 的右邊輸出一個drawable,如圖片。
android:drawableTop //在text 的正上方輸出一個drawable,如圖片。
android:ellipsize //設置當文字過長時,該控件該如何顯示。有如下值設置:”start”—–省略號顯示在開頭;”end”——省略號顯示在結尾;”middle”—-省略號顯示在中間;”marquee” ——以跑馬燈的方式顯示(動畫橫向移動)
android:freezesText //設置保存文本的內容以及光標的位置。
android:gravity //設置文本位置,如設置成“center”,文本將居中顯示。
android:hint //Text 為空時顯示的文字提示信息,可通過textColorHint 設置提示信息的顏色。比較奇怪的是TextView 本來就相當于Label,怎么會不設置Text?!
android:includeFontPadding //設置文本是否包含頂部和底部額外空白,默認為true。
android:inputMethod //為文本指定輸入法,需要完全限定名(完整的包名)。
android:linksClickable //設置鏈接是否點擊連接
android:marqueeRepeatLimit //在ellipsize 指定marquee 的情況下,設置重復滾動的次數(shù),當設置為marquee_forever 時表示無限次。
android:ems //設置TextView 的寬度為N 個字符的寬度。
android:maxEms //設置TextView 的寬度為最長為N 個字符的寬度。
android:minEms //設置TextView 的寬度為最短為N 個字符的寬度。
android:maxLength //限制顯示的文本長度,超出部分不顯示。
android:lines //設置文本的行數(shù),設置兩行就顯示兩行,即使第二行沒有數(shù)據(jù)。
android:maxLines //設置文本的最大顯示行數(shù),與width 或者layout_width 結合使用,超出部分自動換行,超出行數(shù)將不顯示
android:minLines //設置文本的最小行數(shù),與lines 類似。
android:lineSpacingExtra //設置行間距。
android:lineSpacingMultiplier //設置行間距的倍數(shù)。
android:password //以小點”.”顯示文本
android:phoneNumber //設置為電話號碼的輸入方式。
android:scrollHorizontally //設置文本超出TextView 的寬度的情況下,是否出現(xiàn)橫拉條。
android:shadowColor //指定文本陰影的顏色,需要與 shadowRadius 一起使用。
android:shadowRadius //設置陰影的半徑。
android:shadowDx //設置陰影橫向坐標開始位置。
android:shadowDy //設置陰影縱向坐標開始位置。
android:singleLine //設置單行顯示。
android:text //設置顯示文本.
android:textAppearance //設置文字外觀。如“?android:attr/textAppearanceLargeInverse”這里引用的是系統(tǒng)自帶的一個外觀,?表示系統(tǒng)是否有這種外觀,否則使用默認的外觀??稍O置的值如下:textAppearanceButton/textAppearanceInverse/textAppearanceLarge/textAppearanceLargeInverse/textAppearanceMedium/textAppearanceMediumInverse/textAppearanceSmall/textAppearanceSmallInverse
android:textColor //設置文本顏色
android:textColorHighlight //被選中文字的底色,默認為藍色
android:textColorHint //設置提示信息文字的顏色,默認為灰色。與hint 一起使用。
android:textColorLink //文字鏈接的顏色.
android:textScaleX //設置文字之間間隔,默認為1.0f。
android:textSize //設置文字大小,推薦度量單位”sp”,如”15sp”
android:textStyle //設置字形[bold(粗體) 0, italic(斜體) 1, bolditalic(又粗又斜) 2] 可以設置一個或多個,用“|”隔開android:typeface //設置文本字體,必須是以下常量值之一:normal 0, sans 1, serif 2, monospace(等寬字體) 3]
android:height //設置文本區(qū)域的高度,支持度量單位:px(像素)/dp/sp/in/mm(毫米)
android:maxHeight //設置文本區(qū)域的最大高度
android:minHeight //設置文本區(qū)域的最小高度
android:width //設置文本區(qū)域的寬度,支持度量單位:px(像素)/dp/sp/in/mm(毫米)。
android:maxWidth //設置文本區(qū)域的最大寬度
android:minWidth //設置文本區(qū)域的最小寬度