Your Spannables code is fine. You can verify this by setting the text for the TextView.
The problem is the material design of the button on Android 5.0.
<style name="Widget.Material.Button"> <item name="background">@drawable/btn_default_material</item> <item name="textAppearance">?attr/textAppearanceButton</item> <item name="minHeight">48dip</item> <item name="minWidth">88dip</item> <item name="stateListAnimator">@anim/button_state_list_anim_material</item> <item name="focusable">true</item> <item name="clickable">true</item> <item name="gravity">center_vertical|center_horizontal</item> </style>
There are two solutions.
The first is just a TextView as your button and setText with an image on it.
For another (and maybe more correct) you need to expand the button style ( Widget.Material.Button ) as follows:
<style name="BtnStyle" parent="android:Widget.Material.Button"> <item name="android:textAppearance">@null</item> </style>
Then in your layout:
<Button android:id="@+id/test2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Test" style="@style/BtnStyle"/>
After that, you will see the images in the button.
Do not forget that for the version of Android that is lower than 5.0, you must create BtnStyle too, but in a different resource directory (res / values-v14 / style.xml).
Ilya Tretyakov Sep 30 '15 at 7:42 2015-09-30 07:42
source share