Android - TextView textStyle 没有改变

问题描述 投票:0回答:2

我想根据我得到的数据将 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);
}

但是风格根本没有改变(它一直保持大胆)。

android textview
2个回答
1
投票

尝试在最后调用

reserveCount.invalidate()
reserveCount.requestLayout()
强制重画
View


0
投票

尝试一下

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));  
}
© www.soinside.com 2019 - 2024. All rights reserved.