In drawable there is a simple shape:
<?xml version="1.0" encoding="utf-8"?> <shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="15dp"/> <solid android:color="#ffcd7821"/> </shape>
It is the background for RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" tools:context=".MainActivity" android:background="@drawable/shape"> <TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RelativeLayout>
You need to programmatically change the color shape at the start of the action. I do it like this:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); GradientDrawable gd = (GradientDrawable) getResources().getDrawable(R.drawable.shape); gd.setColor(Color.BLUE); }
The color at the start of the activation does not change. But it changes when the restart is activated.
Questions:
Why does the color shape not change at the start ??
How to make the shape change color when you first start activating ??