공부방/Android

How to change color stroke and solid programmatically ?

soycrab 2020. 1. 27. 21:04


Stroke color :

val drawable = view.background as GradientDrawable
drawable.setStroke(3, ContextCompat.getColor(context, R.color.colorWhite)) // width and stroke color

Solid color :

val drawable = view.background as GradientDrawable
drawable.setColor(ContextCompat.getColor(context, R.color.colorWhite)) // solid  color

 

resource_border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorWhite"
/>
<corners android:radius="90dp" />
<stroke
android:width="1dp"
android:color="@color/color_green_sea" />
</shape>

 

 

반응형