protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); SharedPreferences sharepref= PreferenceManager.getDefaultSharedPreferences(this); Boolean swichter =sharepref.getBoolean(this.KEY_PREF_STRING,true); Toast.makeText(this,swichter.toString(),Toast.LENGTH_LONG).show(); if (swichter.toString()=="false"){ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); Intent intent=getIntent(); finish(); startActivity(intent); }else{ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); Intent intent=getIntent(); finish(); startActivity(intent); } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { // launch settings activity startActivity(new Intent(MainActivity.this, SettingsActivity.class)); return true; }
public static final String KEY_PREF_STRING="key_vibrate"; getSupportFragmentManager().beginTransaction() .replace(android.R.id.content,new SettingsFragment()) .commit();
protected void onCreate(Bundle savedInstanceState) { SharedPreferences sharepref = PreferenceManager.getDefaultSharedPreferences(this); Boolean swichter = sharepref.getBoolean(this.KEY_PREF_STRING,true); if (swichter) AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); else AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)