Android/UIテキスト
提供: 初心者エンジニアの簡易メモ
テキスト書き換え
- xmlレイアウト
<TextView android:id="@+id/textView1"
android:text="@string/hello"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
- java
TextView textView1 = (TextView)findViewById(R.id.textView1);
textView1.setText("テスト");
テキストアウトライン設定
- xml
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffffff"
android:shadowColor="#ff000000"
android:shadowDy="0"
android:shadowDx="0"
android:shadowRadius="4"
android:text="test"/>
改行テキスト
- xml
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1、\nテストです\n\n2、てすとです"
android:singleLine="false"
/>
¥nでなく\n (macだとoption n)でなければならない。
中央寄せ
android:gravity="center"
フォントサイズ
android:textSize="18sp"
余白
android:paddingTop="10sp" android:paddingBottom="10sp" android:paddingLeft="10sp" android:paddingRight="10sp"
match_parentとmatch_parent
同じ意味だが、match_parentの方が推奨(android 2.2[API 8]以上)
