android-add top padding to Chip text

Viewed 596

I'm using Chip component from material library in my android app. It is an action chip which has an icon and a text inside. the point is that I need to add some padding to the top of the text in order to bring it down a little a bit.

I have tried to add textAppearance style to the chip, but can not find any style item to do what i need. how to do that?!

        <com.google.android.material.chip.Chip
        android:id="@+id/chip"
        android:layout_width="wrap_content"
        app:chipIcon="@drawable/satisfied"
        app:chipIconTint="#444"
        android:layout_height="wrap_content"
        android:text="my text!"
        android:textAppearance="@style/Widget.App.Chip" />


    <style name="Widget.App.Chip" parent="Widget.MaterialComponents.Chip.Action">
    <item name="android:textSize">14dp</item>
    <item name="android:fontFamily">@font/xyz</item>
    <item name="android:textStyle">bold</item>
    // what item is needed to achieve top padding?!
    </style>
1 Answers

simply: you can't. Chip is designed as is and it extends AppCompatCheckBox and further TextView (doc HERE). so these icons on the left and/or right are compound drawables, not separated Views (e.g. ImageViews), so every padding you will set to Chip will add padding to text and all icons (as this is one View). for your purposes you must create own custom View, easiest way would be probably to create horizontal LinearLayout with childs: TextView and ImageViews on left and right to it, and then you can set additional padding only for text

Related