我有 ExpandableListView 的监听器对于组折叠和展开:
// There is a text view on group layout, no problem there.
@Override
public void onGroupCollapse(int groupPosition) {
// this callback is triggered, however, once the textView is BOLD by onGroupExpanded, the textView is not set back to normal, seems this line of code does nothing...WHY?
textView.setTypeface(textView.getTypeface(), Typeface.NORMAL);
}
@Override
public void onGroupExpand(int groupPosition) {
// it works fine
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
}
正如你在上面看到的,我在组布局中有一个 textView
,当组展开时,我加粗 textView
,如果折叠,我尝试通过 Typeface.NORMAL
将其设置回 unbold。
两个回调都被正确触发,但是,一旦textView
被onGroupExpanded(...)
BOLD> 回调,当 onGroupCollapse(...)
之后被触发时,textView
不会设置回 NORMAL。似乎 onGroupCollapsed(...)
中的代码行什么也没做...为什么?
(再次触发 onGroupCollapse(...)
。没问题!)
最佳答案
如果你在这个 TextView 上使用 android:fontFamily
那么我很确定
textView.setTypeface(null, Typeface.NORMAL);
将更改为默认字体。另一种方法是:
textView.setTypeface(Typeface.create(textView.getTypeface(), Typeface.NORMAL));
最初的问题是,如果样式为 NORMAL,TextView 的 setTypeface
会奇怪地跳过一些内容。我已经在一个版本上对此进行了测试,并且有效。
关于android - 将 TextView 的字体设置为 Typeface.NORMAL 没有任何效果,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47797541/