android - SpannableString not working when using AppCompat theme -
i'm unable spannablestring work when set apptheme theme.appcompat.light.darkactionbar.
i have button , text set spannablestring. when use holo theme text renders expected, when switch appcompat theme span effects seam ignored. how can spannablestring work using appcompat theme?
styles.xml - when switching between 2 themes different results...
<resources> <style name="apptheme" parent="theme.appcompat.light.darkactionbar" /> <!--<style name="apptheme" parent="@android:style/theme.holo.light" />--> </resources>
... button uses spannablestring
public static class placeholderfragment extends fragment { public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); button button = (button) rootview.findviewbyid(r.id.button); string detail = "abc"; string caption = string.format("2 %s", detail); spannable span = new spannablestring(caption); int detailindex = caption.indexof(detail); span.setspan(new stylespan(typeface.bold), 0, detailindex, spannable.span_exclusive_exclusive); span.setspan(new relativesizespan(0.5f), detailindex, detailindex+detail.length(), spannable.span_exclusive_exclusive); button.settext(span); return rootview; } }
well, it's not tied appcompat-v7
. if remove theme stuff entirely, , use default theme, on android 5.0+ theme.material
, , same effect can seen there.
part of material design aesthetic button captions should caps, , implemented wiping out spans. appcompat-v7
works code on pre-5.0 devices, suggesting backported widget effects not include app-caps stuff, , delegating standard widgets on 5.0+.
adding android:textallcaps="false"
button
in layout seems clear problem.
Comments
Post a Comment