I have this Button in my Relative Layout:
<Button
android:id="@+id/gpsButton"
android:layout_width="50sp"
android:layout_height="50sp"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/tableLayout1"
android:background="@drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="GPS"
android:textColor="#ffffff" />
It is linked to this shade:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FF0000"/>
<stroke android:width="2sp" android:color="#fff" />
</shape>
My question is how can I change the colour from the button in my activity?
I've tried it but the app crashed -.- Here is a snippet of my code:
RelativeLayout relLayout = (RelativeLayout) findViewById(R.id.reli);
GradientDrawable bgShape = (GradientDrawable) relLayout.getBackground();
bgShape.setColor(Color.parseColor("#FFFF00"));
What do I wrong? I don't understand how to do this with the view.
Thank you in advance :)