Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Stroke on GradientDrawable Android

I am creating a custom Button and I am using the Drawable.setTintList to have colors for default,pressed and disabled states.
I want to actually add a border to the button, which I am trying by doing:

val d = newGradientDrawableForShape()
d.setShape(GradientDrawable.RECTANGLE)

d.setColor(Color.WHITE)
d.setStroke(20, Color.GREEN) 

With this the border is not visible, however if I do not use tint list then I do see the border.
Is there a way I can use setStroke and TintList?
I tried d.setStroke(width, colorList) and it didn't work either.

like image 800
pixelWorld Avatar asked Aug 14 '26 01:08

pixelWorld


1 Answers

you can use drawable with state example:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <corners android:radius="4dp" />
            <stroke android:width="10dp" android:color="#6699ff" />
        </shape>
    </item>

    <item>
        <shape android:shape="rectangle">
            <corners android:radius="4dp" />
            <stroke android:width="10dp" android:color="#669900" />
        </shape>
    </item>

</selector>

enter image description here

like image 67
serg3z Avatar answered Aug 16 '26 16:08

serg3z