Android - TextView TextStyle をプログラムで設定しますか? 質問する

Android - TextView TextStyle をプログラムで設定しますか? 質問する

textStyleプログラムで属性を設定する方法はありますかTextView? そのような方法はないようですsetTextStyle()

誤解のないよう言っておきますが、私は View / Widget スタイルについて話しているわけではありません。私が話しているのは次のことです。

<TextView
  android:id="@+id/my_text"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Hello World"
  android:textStyle="bold" />

ベストアンサー1

textview.setTypeface(Typeface.DEFAULT_BOLD);

setTypeface は属性 textStyle です。

Shankar V 氏が付け加えたように、以前に設定した書体属性を保持するには、以下を使用できます。

textview.setTypeface(textview.getTypeface(), Typeface.BOLD);

おすすめ記事