Android - TextView textStyle 没有改变
Android - TextView textStyle is not changing
我想根据获得的数据将 TextView 样式从粗体切换为普通。
我是这样做的:
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);
}
但是风格一点都没有变(一直都是粗体)。
试一试
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));
}
尝试在最后调用reserveCount.invalidate()
或reserveCount.requestLayout()
强制重绘View
我想根据获得的数据将 TextView 样式从粗体切换为普通。
我是这样做的:
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);
}
但是风格一点都没有变(一直都是粗体)。
试一试
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));
}
尝试在最后调用reserveCount.invalidate()
或reserveCount.requestLayout()
强制重绘View