2

I create a style, added in my textview xml and worked ok, this way:

<TextView
                        android:id="@+id/userFeedName"
                        style="@style/feeds_user_connected_style"
                        android:text="@string/user_name"
                        />

But I need to create a textview using java and use my style, I tried it:

TextView textView = new TextView(this);

        textView.setTextAppearance(getApplicationContext(), R.style.feeds_user_connected_style);
        textView.setText(R.string.user_name);

But android studio throw the message "setTextAppearance is deprecated". How can I fix it and use my style?

2 Answers2

0

according to the TextView docs you should use setTextAppearance(int) without a context from sdk level 23 and up.

Valentin Kuhn
  • 753
  • 9
  • 25
0

If your compile sdk version is 23, you can use the setTextAppearance method without a context, using only the id if the R.style file.

Also you may refer to this question

Community
  • 1
  • 1
Farhad
  • 12,178
  • 5
  • 32
  • 60