SpannableString does not work when using AppCompat theme

I cannot get SpannableString to work when I install AppTheme in Theme.AppCompat.Light.DarkActionBar.

I have a button, and its text is set using SpannableString. When I use the Golo theme, the text is displayed as expected, but when I switch to the AppCompat theme, the effects effects seam is ignored. How to make SpannableString work using AppCompat theme?

enter image description here

styles.xml - when switching between these two themes, I get very different results ...

<resources>
  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" />
  <!--<style name="AppTheme" parent="@android:style/Theme.Holo.Light" />-->
</resources>

... for my button that uses a 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;
    }
}
+4
source share
1 answer

, appcompat-v7. , Android 5.0+ Theme.Material, , .

Material Design , , , , , . appcompat-v7 5.0, , , 5.0 +.

android:textAllCaps="false" Button , , .

+8

All Articles