I have listeners for ExpandableListView for group collapsed and expanded:
// 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);
}
As you can see above, I have a textView
in group layout, when group is expanded, I bold the textView
, if collapsed, I try to set it back to unbold by Typeface.NORMAL
.
Both callbacks are triggered correctly, however, once the textView
is BOLD by onGroupExpanded(...)
callback, the textView
is not set back to NORMAL when onGroupCollapse(...)
is triggered afterwards. Seems the line of code in onGroupCollapsed(...)
does nothing...WHY?
(Again, onGroupCollapse(...)
is triggered. No problem there!)
The android:textStyle attribute can be used to put emphasis on the text. The possible values are: normal , bold , italic . You can also specify bold|italic .
Android 8.0 (API level 26) introduces a new feature, Fonts in XML, which lets you use fonts as resources. You can add the font file in the res/font/ folder to bundle fonts as resources. These fonts are compiled in your R file and are automatically available in Android Studio.
Android: Tap and hold the text you're entering in the text field, then choose Bold, Italic, or More . Tap More to choose Strikethrough or Monospace. iPhone: Tap the text you're entering in the text field > Select or Select All > B_I_U. Then, choose Bold, Italic, Strikethrough, or Monospace.
If you use android:fontFamily
on this TextView then I am pretty sure
textView.setTypeface(null, Typeface.NORMAL);
will change to the default font. Another way to do this is:
textView.setTypeface(Typeface.create(textView.getTypeface(), Typeface.NORMAL));
The original problem is that TextView's setTypeface
with the style oddly skips over some stuff if the style is NORMAL. I've tested this on one version, and it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With