启动应用程序时更改背景颜色

时间:2014-01-07 16:30:58

标签: android

我想要做的是,当我启动应用程序时,例如:颜色为绿色,然后我需要按下oder中的按钮(启动颜色)以在这种情况下启动具有绿色背景的应用程序。我试过但没有改变

        View myView = getLayoutInflater().inflate(R.layout.radiogroup, null);
        RadioGroup myRadioGroup = (RadioGroup)
        myView.findViewById(R.id.radioGroup);

        int radioGroupId = myRadioGroup.getCheckedRadioButtonId();
        RadioButton myCheckedButton = (RadioButton)
        myView.findViewById(radioGroupId);
        int index = myRadioGroup.indexOfChild(myCheckedButton);

        AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
        builder2.setView(myView);
        builder2.setMessage("Choose Startup Color:");
        builder.setPositiveButton("Set Startup Color", new      DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 

                    switch(which)
                     {
                         case R.id.White:
                                myLayout.setBackgroundColor(Color.WHITE);
                                 break;

                         case R.id.Black:
                                 myLayout.setBackgroundColor(Color.BLACK);
                                 break;

                         case R.id.Red:
                                myLayout.setBackgroundColor(Color.RED);
                                 break;

                         case R.id.Green:
                                myLayout.setBackgroundColor(Color.GREEN);           
                                 break;

                         case R.id.Yellow:
                                myLayout.setBackgroundColor(Color.YELLOW);
                                break;

                     }

            }

         });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
            }
         });
        builder.show();

0 个答案:

没有答案