facebook twitter hatena line email

Android/UIテキスト

提供: 初心者エンジニアの簡易メモ
2015年5月20日 (水) 03:16時点における127.0.0.1 (トーク)による版 (ページの作成:「==テキスト書き換え== *xmlレイアウト <<nowiki />TextView android:layout_width="match_parent" android:id="@+id/textView1" android:text="...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

テキスト書き換え

  • xmlレイアウト
<TextView android:layout_width="match_parent"
          android:id="@+id/textView1"
          android:text="@string/hello"
          android:layout_height="wrap_content">
</TextView>
  • 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でなければならない。

中央寄せ

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]以上)

参考: http://android49.blog.fc2.com/blog-entry-20.html