2
Hey, guys, I’m having a little doubt I already did a little snooping on the internet and I haven’t found it yet maybe it’s not possible, but come on..
For example I have a button on this button I play random colors on it, I have a List Colors = new Arraylist(); and in this list I keep the colors in Hexadecimal, so far without problems I use the Collections.shuffle() and I take a color randomly from the list and on the button I use the bt1.setBackgroundColor(), my biggest doubt is I want my application Buttons to have rounded corners, I know I have to use something like this
cantosredondodos.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#33DDFF" />
<corners android:radius="4dp" />
</shape>
but if I put this xml as background there in the xml button
<Button
android:text="Button"
android:textAllCaps="false"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:background="@drawable/cantosredondodos"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
the backgroud I defined earlier in the code will overwrite the xml part I want to do Radius, would you have a solution? to do everything in the application code? I even thought about making several xmls but I believe it wouldn’t look too cool, as I have more than 10 Buttons wouldn’t be a very viable thing...
opa thanks, here in my case I gave a small adapted : ic void customView(int backgroundColor, Button value){ Shape = new Gradientdrawable(); Shape.setShape(Gradientdrawable.RECTANGLE); Shape.setCornerRadii(new float[] { 8, 8, 8, 8, 0, 0, 0, 0 }); Shape.setColor(backgroundColor); //Shape.setStroke(3, borderColor); value.setBackgroundDrawable(Shape); } the colors I have already added to the list in all 18 colors, and in my case I already use the Collections.shuffle not to repeat the colors, but thanks solved my problem
– Steve Rogers
@Cool Rogersmarques... I put it like this for you to adapt, because it’s in a very generic way. abs. good luck
– viana