Calyth
Calyth

Reputation: 1673

Programmatically use setTextSize to ?attr/textAppearanceLarge

I'm tinkering with a custom preference right now, and I want to give it a label using TextView. However I can't seem to find a way to specify the text size to "large" using setTextView()

What am I missing here?

Upvotes: 13

Views: 13619

Answers (2)

EMalik
EMalik

Reputation: 2515

As the syntax has changed since starting API Level 23 (Marshmallow) also a few users mentioned that android.R.attr.textAppearanceLarge did not work for them as it did not work for me. Here is the updated version...

Button b = new Button(getContext());

if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M )
    b.setTextAppearance( android.R.style.TextAppearance_Medium );
else
    b.setTextAppearance( getContext(), android.R.style.TextAppearance_Medium );

Upvotes: 1

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

TextView title = new TextView(context);
title.setTextAppearance(context, android.R.attr.textAppearanceLarge);

or try

setTextAppearance(context, android.R.style.TextAppearance_Large);

use the above code and try

Upvotes: 40

Related Questions