android - AppCompat v22.1.0 not theming all xml widgets correctly for fragments -
when using xml based layouts using appcompat 22.1.0 not supported widgets tinted or material themed fragments using android 4.4.
i see behavior following widgets (others not tested):
- radiobutton (no tint color)
- checkbox (no tint color)
- spinner (device default theme applied)
- edittext (device default theme applied)
- ratingbar (device default theme applied)
- button (device default theme applied)
it used work in appcompat v22.0.0.
screenshot (left 4.4, right 5.0):
mainactivity.java:
public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); if (savedinstancestate == null) { getsupportfragmentmanager() .begintransaction() .add(r.id.container, new placeholderfragment()) .commit(); } } 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); return rootview; } } }
fragment_main.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <radiobutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="radiobutton test"/> <checkbox android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="checkbox test"/> <spinner android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/somestrings"/> </linearlayout>
themes.xml
<resources> <style name="apptheme" parent="theme.appcompat.light.darkactionbar"></style> </resources>
this reported bug: https://code.google.com/p/android/issues/detail?id=169760
a temporary workaround use fragment parent activity layoutinflater: getactivity().getlayoutinflater()
instead of supplied layoutinflater in oncreateview method.
example:
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = getactivity().getlayoutinflater().inflate(r.layout.fragment_main, container, false); return rootview; }
note: solution use special appcompat widgets in xml layout:
- android.support.v7.widget.appcompatradiobutton
- android.support.v7.widget.appcompatcheckbox
- android.support.v7.widget.appcompatspinner
but mean need replace every single widget appcompat one.
Comments
Post a Comment