0

ユーザーが背景色を選択できるオプションを作成しようとしています。ただし、ユーザーがオプションを選択すると、デフォルトで緑になります。アプリをアンインストールすると、背景色はデフォルトで緑色になります。オプションの緑を削除すると、デフォルトで上の色(青)になります。どこが悪いのかわからない。任意の提案をいただければ幸いです。

public class UserMenu extends Activity implements OnClickListener {
Button preview;
Spinner spinnerColor;
SharedPreferences preferences;
public static String theme = "Blue";
    @Override
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         preferences = getSharedPreferences("StylePref", 0);
         theme = preferences.getString("THEME", "Red");
        if(theme.equals("Red"));
        {
            setTheme(R.style.Theme_Red);
        }
        if(theme.equals("Blue"));
        {
            setTheme(R.style.Theme_Blue);
        }
        if(theme.equals("Green"));
        {
            setTheme(R.style.Theme_Green);
        }

        setContentView(R.layout.activity_user_menu);
        System.out.println(theme);
        spinnerColor = (Spinner) findViewById(R.id.spinnerColorMenu);
        preview = (Button)findViewById(R.id.previewButton);
           preview.setOnClickListener(this);

    }

    public void onClick(View v)


    {
        SharedPreferences.Editor preferencesEditor = preferences.edit();
        String bgColor = spinnerColor.getSelectedItem().toString();
        preferencesEditor.putString("THEME", bgColor);
        preferencesEditor.commit();

        if(bgColor.equals("Red"))
         {
            //Intent intent = getIntent();
            //intent.putExtra("Theme", "Red");
          finish();
          //startActivity(intent);
         }
         else if(bgColor.equals("Blue"))
         {
             Intent intent = getIntent();
            //intent.putExtra("Theme", "Blue");
           finish();
           startActivity(intent);
         }

         else if(bgColor.equals("Green"))
         {
             Intent intent = getIntent();
            //intent.putExtra("Theme", "Green");
           finish();
           startActivity(intent);
         }
    }
}
4

2 に答える 2

1
if(theme.equals("Green"));

ifブロックの最後にあるセミコロンを削除します。

于 2012-11-07T15:32:51.120 に答える
1

いくつかのセミコロンが適切ではありません。

        if(theme.equals("Red")); <--- Remove this ;
        {
            setTheme(R.style.Theme_Red);
        }
        if(theme.equals("Blue")); <--- Remove this ;
        {
            setTheme(R.style.Theme_Blue);
        }
        if(theme.equals("Green")); <--- Remove this ;
        {
            setTheme(R.style.Theme_Green);
        }
于 2012-11-07T15:33:08.717 に答える