liguofeng29’s blog

個人勉強用ブログだっす。

AndroidのUI - TextView

textView.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp">

<!-- Textサイズ、色、影 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="なぜか影でない"
android:textSize="20pt"
android:textColor="#f00"
android:shadowColor="#00f"
android:shadowDx="1.5"
android:shadowDy="1.5"
android:shadowRadius="1.5"
/>

<!-- すべて大文字 -->
<!-- 一行で表示 -->
<!-- 中央省略(・・・) -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="middle"
android:textAllCaps="true"
android:text="すべて大文字&一行表示aBcD123456789012345678901234501234&中央省略" />

<!-- Hyper link -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="email|phone"
android:text="メールはtest@test.com 電話は03123456789" />

<!-- パスワード入力 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:password="true"
android:text="Hello World!" />

<!-- チェックTextView -->
<CheckedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckedTextView" />

<!-- border設定 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Border設定"
android:textSize="20pt"
android:background="@drawable/bg_border1"/>

<!-- 背景設定TextView-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="背景設定"
android:textSize="20pt"
android:background="@drawable/bg_border2"/>

</LinearLayout>
 
 

bg_border1.xml
 
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#0000" />
<stroke
android:width="4px"
android:color="#f00" />
</shape>
 
bg_border2.xml
 
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 四角の丸い角度 -->
<corners
android:topLeftRadius="20px"
android:topRightRadius="20px"
android:bottomRightRadius="20px"
android:bottomLeftRadius="20px" />

<!-- 周りwidthと色 -->
<stroke
android:width="4px"
android:color="#f0f" />

<!-- グラデーション -->
<gradient
android:startColor="#f00"
android:centerColor="#0f0"
android:endColor="#00f"
android:type="sweep" />
</shape>