Dark And Light Theme In Android App | Android Studio Tutorial 2020 | Simple Method

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ธ.ค. 2020
  • This video shows you how you can set dark theme in your android application.
    Also implementing the functionality to switch between dark, light and system default theme.
    From (Android 10) and above versions we have settings to set dark models it is necessary to make your app support both light and dark mode for better user experience.
    So As the android official documentation, these are the three ways to enable Dark theme in Android 10 (API level 29) and higher:
    - Use the system setting (Settings - Display - Theme) to enable Dark theme.
    - Use the Quick Settings tile to switch themes from the notification tray (once enabled).
    - On Pixel devices, selecting the Battery Saver mode enables Dark theme at the same time. Other OEMs may or may not support this behaviour.
    Get project source code : github.com/solotechky/DarkTheme
    Dependencies and plugins used in project:
    - dependencies {
    implementation 'com.google.android.material:material:1.2.1'
    }
    - plugins{
    id 'kotlin-android-extensions'
    }
    Subscribe to this channel:
    / @solotechky9548
    HAPPY CODING...
    #android #darktheme #androidstudio

ความคิดเห็น • 23

  • @tristangrobler4950
    @tristangrobler4950 3 ปีที่แล้ว +17

    For JAVA if anyone, like me needs the code. . .
    After setting up your variables etc, this would be how you would do it if you were using Theme.MaterialComponents.NoActionBar:
    if (isChecked) {
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    } else {
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    }
    For AppCompact theme as shown in the video you would use:
    if(isChecked)){
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    }else{
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    }
    I have been trying for ages to find this simple trick. Thanks again for the video. Hope this helps someone else too. At least the video got me going on the right path!!

    • @solotechky9548
      @solotechky9548  3 ปีที่แล้ว +5

      It will be very helpfu, thank u

    • @avvjt
      @avvjt 2 ปีที่แล้ว

      hy bro i need help ....i tryed this but my app got crashed

    • @tristangrobler4950
      @tristangrobler4950 2 ปีที่แล้ว

      @@avvjt what is causing the crash?

  • @iamkdblue
    @iamkdblue 3 ปีที่แล้ว +2

    the video explains very well, which google tutorials cant do !

  • @AnkitDasOfficial
    @AnkitDasOfficial 3 ปีที่แล้ว +1

    Thanks! Helped me a lot

  • @freezone1780
    @freezone1780 3 ปีที่แล้ว +1

    thanks for making this video geat content,

  • @user-ky3zr7zp2b
    @user-ky3zr7zp2b 3 ปีที่แล้ว

    thank u for this viedo , very nice

  • @kesavguru415
    @kesavguru415 ปีที่แล้ว

    Great video bro 🔥

  • @Akshaykumar-xr9yj
    @Akshaykumar-xr9yj 2 ปีที่แล้ว

    thnk your so mch

  • @im.jrmkrc
    @im.jrmkrc 3 ปีที่แล้ว +1

    very helpful

  • @anurajms
    @anurajms 3 ปีที่แล้ว

    thank you

  • @codesouls2441
    @codesouls2441 3 ปีที่แล้ว +1

    Your explanation is very nice

  • @Shadow67947
    @Shadow67947 3 ปีที่แล้ว +1

    Can you please do the one for multiple activity

  • @marlonlom
    @marlonlom 3 ปีที่แล้ว

    so, no point for saving the theme changes ehen pressing the buttons? nor, no preference screen for that? :(

  • @87nehal
    @87nehal 3 ปีที่แล้ว +2

    The theme changes back after the app is reset.

    • @solotechky9548
      @solotechky9548  3 ปีที่แล้ว +1

      Save the theme value in shared preference

  • @87nehal
    @87nehal 3 ปีที่แล้ว +1

    Can you provide java code ?

  • @ailing21
    @ailing21 2 ปีที่แล้ว

    I need to find this for java :(

    • @marc988
      @marc988 2 ปีที่แล้ว +1

      There's a pinned comment above which answers exactly your question :)

    • @ailing21
      @ailing21 2 ปีที่แล้ว

      Thxs @@marc988 :)