public class MainActivity extends AppCompatActivity { RadioButton radioButton2,radioButton3; SharedPreferences sharedPreferences=this.getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor=sharedPreferences.edit(); String veri=sharedPreferences.getString("kullanici",""); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(veri.equals(AppCompatDelegate.MODE_NIGHT_NO)) radioButton2.setChecked(true); else radioButton3.setChecked(true); } public void onRadioClicked(View view){ SharedPreferences sharedPreferences=this.getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor=sharedPreferences.edit(); String veri=sharedPreferences.getString("kullanici",""); boolean checked=((RadioButton)view).isChecked(); switch (view.getId()){ case R.id.radioButton2: if(checked){ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); editor.putInt("tema",AppCompatDelegate.MODE_NIGHT_NO); editor.apply(); } break; case R.id.radioButton3: if(checked){ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); editor.putInt("tema",AppCompatDelegate.MODE_NIGHT_YES); editor.apply(); } break; } } protected void onDestroy() { sharedPreferences=null; super.onDestroy(); } }