This is my first app so finding my way around bit by bit and have been experimenting a little and would like to change the background colour to a colour from a list.
Currently it loads a white background specified in strings.xml
<color name="all_white">#FFFFFF</color>
This is used in main.xml:
android:background="@color/all_white"
Ideally I would like to change the colour in OnCreate() to a colour of my choice. I have tried setBackgroundDrawable but it doesnt seem to work?
This is my code:
public class TestActivity extends Activity
{
double dimValPercent = 100;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SetDimLevel(dimValPercent);
SetBackground();
return;
}
public void SetBackground()
{
getWindow().setBackgroundDrawable( new ColorDrawable
(color.all_blue) );
return;
}
void SetDimLevel(double dimVal)
{
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = (float) (dimVal/ 255.0);
getWindow().setAttributes(lp);
return;
}
}