我想根据我得到的数据将 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.invalidate()
或 reserveCount.requestLayout()
强制重画 View
尝试一下
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));
}