Issue
I can't center my drawableLeft icon.
I can easily put icon on the left of text, but if I set gravity to center, then only text is centered, but no icon.
<Button
android:id="@+id/patient_list_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/patientList"
android:drawableLeft="@drawable/ic_icon_two_heads"
android:layout_marginBottom="15dp"
style="@style/darkBlueButtonWithImage"/>
This is what I want:
This is what I have:
<style name="darkBlueButtonWithImage">
<item name="android:drawablePadding">10dp</item>
<item name="android:textColor">@color/white</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:background">@drawable/radius_dark_blue_button</item>
<item name="android:gravity">center_vertical|left</item>
<item name="android:drawableTint">@color/white</item> <!-- has to be set in activity.java -->
</style>
How can I achieve this?
Solution
Finally, after all these years, we have possibility to achieve such behavior in simple and intuitive way.
All you have to do is use MaterialButton from Google Material library. Then use style with icon. After that you can use app:iconGravity
property and set it to textStart
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.Icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some text"
app:iconGravity="textStart"
app:icon="@drawable/some_icon" />
Answered By - KaMyLL
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.