dark theme not changing button android studio code example

Example 1: dark mode change immediately swift

guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
   return
}
appDelegate.changeTheme(themeVal)


// App Delegate Change Theme method
func changeTheme(themeVal: String) {  
  if #available(iOS 13.0, *) {
     switch themeVal {
     case "dark":
         window?.overrideUserInterfaceStyle = .dark
         break
     case "light":
         window?.overrideUserInterfaceStyle = .light
         break
     default:
         window?.overrideUserInterfaceStyle = .unspecified
     }
  }
}

Example 2: android studio change button color programmatically

// If you're in an activity:
Button11.setBackgroundColor(getResources().getColor(R.color.red));
// OR, if you're not: 
Button11.setBackgroundColor(Button11.getContext().getResources().getColor(R.color.red));