Skip to content

Instantly share code, notes, and snippets.

View sakshampruthi's full-sized avatar

Saksham Pruthi sakshampruthi

View GitHub Profile
when(SaveSharedPrefernce.getChecktheme(applicationContext)) {
0 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
class MainActivity : AppCompatActivity() {
var selection: String? = null
var checked_item = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val theme = applicationContext.resources.getStringArray(R.array.theme)
object SaveSharedPrefernce {
const val CHECKTHEME = "checkTheme"
fun getSharedPreferences(ctx: Context?): SharedPreferences {
return PreferenceManager.getDefaultSharedPreferences(ctx)
}
fun setChecktheme(context: Context?, check: Int) {
val editor = getSharedPreferences(context).edit()
editor.putInt(CHECKTHEME, check)
editor.apply()