Android:TextView(EditText)のXML Attributesをある程度試してみる
どーもー。ブンブン丸でーす。
毎週火曜担当から隔週金曜担当に異動になりました。はい。
さて、今回は、使った事がない人は居ない(と思われる)TextView(EditText)についてです。
先日、とある事をググっていた時に目にした記事の中に、TextViewのXML Attributesで見慣れぬものがありました。
おぉ、こんなものがあったのかぁ。目から鱗とは正にこの事です。
ということで今回はタイトルの通り、TextView(EditText)のXML Attributesをある程度試したいと思います。
XML Attributes の一覧
- android:autoLink
- android:autoText
- android:bufferType
- android:capitalize
- android:cursorVisible
- android:digits
- android:drawableBottom
- android:drawableLeft
- android:drawableRight
- android:drawableTop
- android:drawablePadding
- android:editable
- android:editorExtras
- android:ellipsize
- android:ems
- android:freezesText
- android:gravity
- android:height
- android:hint
- android:imeActionId
- android:imeActionLabel
- android:imeOptions
- android:includeFontPadding
- android:inputMethod
- android:inputType
- android:lineSpacingExtra
- android:lineSpacingMultiplier
- android:lines
- android:linksClickable
- android:marqueeRepeatLimit
- android:maxEms
- android:maxHeight
- android:maxLength
- android:maxLines
- android:maxWidth
- android:minEms
- android:minHeight
- android:minLines
- android:minWidth
- android:numeric
- android:password
- android:phoneNumber
- android:privateImeOptions
- android:scrollHorizontally
- android:selectAllOnFocus
- android:shadowColor
- android:shadowDx
- android:shadowDy
- android:shadowRadius
- android:singleLine
- android:text
- android:textColor
- android:textColorHighlight
- android:textColorHint
- android:textColorLink
- android:textScaleX
- android:textSize
- android:textStyle
- android:typeface
- android:width
Attributesを確認してみる
それでは上から順に見て行きましょう。
android:autoLink
none, web,email,phone,map,all
URLやメールアドレス、住所などのリンクを自動的にクリック可能なリンクに変換するかどうかを制御します。
文字列にリンクを設定したい時にこの属性を追加するだけで実現でき、リンク時には対応したアプリが選択できるようになります。
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="web" android:text="https://nvtrlab.jp" />
android:autoText※
非推奨です
android:bufferType
#省略
android:capitalize※
非推奨です
android:cursorVisible
カーソルの表示/非表示を指定します。
true: 表示 false:非表示
android:digits
android:drawableBottom,drawableLeft,drawableRight,drawableTop
それぞれTextViewの下側、左側、右側、上側に描画するオブジェクトを指定します。
android:drawableStart
TextViewのはじめに描画するオブジェクトを指定します。
android:drawableEnd
TextViewの終わりに描画するオブジェクトを指定します。
android:drawablePadding
drawableBottom等で配置したオブジェクトとのpaddingを指定します。
android:editable※
非推奨です
android:editorExtras
#省略
android:ellipsize
長い文字列を”…”を使って省略させます。
GALAXY SII のICS では “…”が”.”にさらに省略されてました。
android:ems
(em)単位での長さを指定します。
android:fontFamily
#省略
android:freezesText
#省略
android:gravity
#省略
android:height
#省略
android:hint
android:imeActionId、android:imeActionLabel、android:imeOptions
android:includeFontPadding
上下に十分な余白を設定するか、またはフォントに含まれる本来の余白を使用するかを指定します。
android:inputMethod※
非推奨です
android:inputType
入力する文字に制限を掛ける場合に指定します。
ソフトキーボードも変化します。
android:lineSpacingExtra
行間を単位とともに指定します。
android:lineSpacingMultiplier
行間を比率で指定します。
android:lines
行数を指定します。
android:linksClickable
autoLinkで貼られたリンクを、クリックできるかどうかを指定します。
デフォルト値がtrueなのでクリック出来るようになっています。
ところでこの値をfalseにする利点はあるのでしょうか?
あぁ、文字列に下線が引けますね。
android:marqueeRepeatLimit
android:ellipsizeで”marquee”を指定した時のスクロール回数を指定します。
android:maxEms
#省略
android:maxHeight
#省略
android:maxLength
最大文字数を指定します。
android:maxLines
最大で表示する行数を指定します。
android:maxWidth
#省略
android:minEms
#省略
android:minHeight#省略
android:minLines
#省略
android:minWidth
#省略
android:numeric※
非推奨です。
android:password※
非推奨です。
android:phoneNumber※
非推奨です。
android:privateImeOptions
#省略
android:scrollHorizontally
#省略
android:selectAllOnFocus
テキストが選択可能な場合、Viewにフォーカスが当たった時にテキストを全選択するか指定します。
android:shadowColor
テキストの影の色を指定します。
android:shadowDx,android:shadowDy,android:shadowRadius
テキストの影を指定します。
shadowDx:横位置
shadowDy:縦位置
shadowRadius:影の半径
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:shadowColor="#00ffff" android:shadowDx="1.5" android:shadowDy="1.5" android:shadowRadius="2" android:text="shadowColor" android:textSize="20sp" android:visibility="visible" />
android:singleLine
テキストを1行のみの表示にします。
android:text
表示するテキストを指定します。
android:textAllCaps
#省略
android:textAppearance
テキストの大きさを既定のスタイルで指定します。
小さいサイズ:?android:attr/textAppearanceSmall
普通サイズ:?android:attr/textAppearanceMedium
大きいサイズ:?android:attr/textAppearanceLarge
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="textAppearanceLarge" android:textAppearance="?android:attr/textAppearanceLarge" />
android:textColor
テキストの色を指定します。
android:textColorHighlight
android:textColorHint
ヒントテキストの色を指定します。
android:textColorLink
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="web" android:text="https://nvtrlab.jp" android:textColorLink="#ff0000" android:textSize="20sp" android:visibility="visible" />
android:textIsSelectable
TextViewのテキストを選択できるようにするか指定します。(API Level 11以降)
android:textScaleX
<TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textScaleX="1.0" android:text="textScaleX 1.0f" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textScaleX="1.5" android:text="textScaleX 1.5f" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textScaleX="2.0" android:text="textScaleX 2.0f" />
android:textSize
テキストの大きさを指定します。
android:textStyle
テキストのスタイルの指定をします。
じぇじぇ。SC-02C は italicを指定しても変化がないようです。
フォントを変更したところ、italicが有効になりました。どうやら標準フォントではダメなようです。
SC-01Cでは標準フォントでもitalic 指定は有効なようです。
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Normal" android:textSize="20sp" android:textStyle="normal" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="bold" android:textSize="20sp" android:textStyle="bold" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="italic" android:textSize="20sp" android:textStyle="italic" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="bold | italic" android:textSize="20sp" android:textStyle="bold|italic" />
android:typeface
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Normal" android:textSize="20sp" android:typeface="normal" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="sans" android:textSize="20sp" android:typeface="sans" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="serif" android:textSize="20sp" android:typeface="serif" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="monospace" android:textSize="20sp" android:typeface="monospace" />
android:width
#省略
コメントをどうぞ