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
Use TextViewCompat
from support library:
TextViewCompat.setTextAppearance(tv, android.R.style.TextAppearance_Medium);
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);
}
For API > 23, do :
tv.setTextAppearance(android.R.style.TextAppearance_Medium);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With