MainActivity.kt package com.example.jetpack import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.preference.PreferenceManager import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Get the preferences val prefs = PreferenceManager.getDefaultSharedPreferences(this) // Get the user dark theme settings val isDarkTheme = prefs.getBoolean("key_dark_theme",false) textView.text ="Dark Theme Enabled ? $isDarkTheme" btn.setOnClickListener{ // Load the settings fragment supportFragmentManager .beginTransaction() .replace(R.id.linearLayout,MySettingsFragment()) .commit() } } } activity_main.xml <?xml v...
Android, .NET C#, Flutter, and Many More Programming tutorials.