LoginSignup
1
0

More than 3 years have passed since last update.

【Androidを使い熟す!】TextViewについて

Posted at
※Android技術者認定にも役に立ちます!

TextView

テキストを表示するView

TextViewクラス宣言

java
TextViewクラスの変数
TextView textView = findViewById(R.id.text);

TextViewクラスのインスタンス化
(コードで書く場合)
TextView textView = new TextView(this);

よく使う機能

・テキストセット

java
※直接導入
textView.setText("文字");

※リソース
textView.setText(R.string.text);

・フォントサイズ

java
※直接導入
textView.setTextSize(1);

・フォントスタイル

java
※直接導入
textView.setTypeface(Typeface.DEFAULT);

Typeface種類
Typeface  Typeface.DEFAULT
Typeface  Typeface.DEFAULT_BOLD
Typeface  Typeface.DEFAULT_BOLD_ITALIC
Typeface  Typeface.DEFAULT_ITALIC

Tip
-フォントファイル利用の場合
Typeface typeface = Typeface.createFromAsset(getAssets(), "APJapanesefont.ttf");
textView.setTypeface(typeface);

・フォント色

java
RGB
textView.setTextColor(0xffff0000);
Colorクラス
textView.setTextColor(Color.RED);
textView.setTextColor(Color.parseColor("#00ff00"));
※リソース
textView.setTextColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));

Tip

・setTextのメソッドは【String】Typeの値を入れること!Integerの値を入れると怒られる。
・Stringクラスをよく使うことになる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0