Home > Blockchain >  Android - TextView textStyle is not changing
Android - TextView textStyle is not changing

Time:10-27

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).

CodePudding user response:

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

CodePudding user response:

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));
}

  • Related