Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTextAppearance deprecated android how to use?

Tags:

android

 layout=(RelativeLayout)findViewById(R.id.relate);
                TextView tv = new TextView(DetailActivity.this);
                layout.addView(tv);
                tv.setTextAppearance(DetailActivity.this, android.R.style.TextAppearance_Medium);
                tv.setGravity(Gravity.CENTER_HORIZONTAL);
                tv.setText("Hello Man");

Here is my code how to use setTextAppearance for API > 23

Help Appreciated

like image 327
Jitesh Lakhwani Avatar asked Jul 05 '16 09:07

Jitesh Lakhwani


3 Answers

Use TextViewCompat from support library:

TextViewCompat.setTextAppearance(tv, android.R.style.TextAppearance_Medium);
like image 191
R. Zagórski Avatar answered Sep 20 '22 10:09

R. Zagórski


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                titleTextView.setTextAppearance(R.style.TextAppearance_MaterialComponents_Headline6);
            } else {
                titleTextView.setTextAppearance(context, R.style.TextAppearance_MaterialComponents_Headline6);
            }
like image 26
Sourav Bagchi Avatar answered Sep 19 '22 10:09

Sourav Bagchi


For API > 23, do :

tv.setTextAppearance(android.R.style.TextAppearance_Medium);
like image 41
Christian Avatar answered Sep 23 '22 10:09

Christian