Martin
Martin

Reputation: 2904

Android - TextView textStyle is not changing

I want to switch TextView style from Bold to Normal based on data I got.

I'm doing it like this:

reserveCount.setText("Reservations " + reservationCount);
if(reservationCount<20){
  Log.i("reserveCount", "typeface: NORMAL");
  reserveCount.setTypeface(reserveCount.getTypeface(), Typeface.NORMAL);
} else {
  Log.i("reserveCount", "typeface: BOLD");
  reserveCount.setTypeface(reserveCount.getTypeface(), Typeface.BOLD);
}

But style is not changing at all (it stays bold all the time).

Upvotes: 0

Views: 164

Answers (2)

DroidFlutter
DroidFlutter

Reputation: 1287

Try it like

reserveCount.setText("Reservations " + reservationCount);  
if(reservationCount<20){
  Log.i("reserveCount", "typeface: NORMAL"); 
  reserveCount.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
} else {
  Log.i("reserveCount", "typeface: BOLD");  
  reserveCount.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));  
}

Upvotes: 0

snachmsm
snachmsm

Reputation: 19223

try to call reserveCount.invalidate() or reserveCount.requestLayout() at the end for forcing redraw View

Upvotes: 1

Related Questions