mercredi 30 août 2017

Is it possible to transform this into kotlin or java code lines without using XML?

This is the XML file that generates the images below, i need to change colors dynamically in my code so I'm trying to reproduce this straight in Kotlin, but I can not play the same properties and behaviors found in XML and i mainly need to change colors.

<item><shape>//selector_1.xml
    <solid android:color="@color/colorPrimary"/>
    <stroke
        android:width="1dp"
        android:color="@android:color/holo_orange_dark" />
    <corners
        android:radius="10dp" />
    <gradient
        android:angle="225"
        android:endColor="@android:color/transparent"
        android:startColor="@android:color/background_light" />

</shape></item>

<item><selector>
    <item android:state_checked="true"><shape>
        <stroke
            android:width="15dp"
            android:color="@android:color/transparent" />
        <corners
            android:radius="5dp" />
        <gradient
            android:angle="135"
            android:endColor="@android:color/transparent"
            android:startColor="#FF1f00f0" />
    </shape></item>
</selector></item>

<CheckBox
    android:id="@+id/chk_1"
    android:layout_width="36dp"
    android:layout_height="36dp"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:background="@drawable/selector_1"
    android:button="@drawable/selector_1" />

enter image description here

val shape2 = GradientDrawable()
shape2.setSize( 46, 46 )
shape2.setColor( Color.BLUE )
shape2.cornerRadius = 10f
holder?.chkCol1?.buttonDrawable = shape2

I tried in many ways but unfortunately I could not.




Aucun commentaire:

Enregistrer un commentaire