I have three difficulty modes for my app; Easy, Medium, and Hard. I have a variable that keeps track of the difficulty (0-2). How can I use this variable to change the background color of my app? For example, when the mode is easy I want the background to be green, yellow for medium, and red for hard.
Here is what I have in my layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/myBackground" >
</RelativeLayout>
And I have the string resource:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="myBackground">#01CC18</color>
</resources>
However, what I want to do is be able to change the background in the program itself instead of in the xml layouts. Can this be done?
Fill your main view with a LinearLayout. Then get a handle to this layout:
You can use this handle to update the background color whenever your difficulty changes: