Support day/night theme in custom tabs

This commit is contained in:
Mygod
2019-08-12 09:46:03 +08:00
parent a72075ef2e
commit 75cc9a8f87
4 changed files with 16 additions and 6 deletions

View File

@@ -75,7 +75,7 @@ androidExtensions {
dependencies { dependencies {
kapt "androidx.room:room-compiler:$roomVersion" kapt "androidx.room:room-compiler:$roomVersion"
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.browser:browser:1.0.0' implementation 'androidx.browser:browser:1.2.0-alpha07'
implementation 'androidx.core:core-ktx:1.1.0-rc03' implementation 'androidx.core:core-ktx:1.1.0-rc03'
implementation 'androidx.emoji:emoji:1.0.0' implementation 'androidx.emoji:emoji:1.0.0'
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"

View File

@@ -8,6 +8,7 @@ import android.content.res.Configuration
import android.net.ConnectivityManager import android.net.ConnectivityManager
import android.net.wifi.WifiManager import android.net.wifi.WifiManager
import android.os.Build import android.os.Build
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
@@ -78,8 +79,14 @@ class App : Application() {
val hasTouch by lazy { packageManager.hasSystemFeature("android.hardware.faketouch") } val hasTouch by lazy { packageManager.hasSystemFeature("android.hardware.faketouch") }
val customTabsIntent by lazy { val customTabsIntent by lazy {
CustomTabsIntent.Builder() CustomTabsIntent.Builder().apply {
.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)) setColorScheme(CustomTabsIntent.COLOR_SCHEME_SYSTEM)
.build() setColorSchemeParams(CustomTabsIntent.COLOR_SCHEME_LIGHT, CustomTabColorSchemeParams.Builder().apply {
setToolbarColor(ContextCompat.getColor(app, R.color.light_colorPrimary))
}.build())
setColorSchemeParams(CustomTabsIntent.COLOR_SCHEME_DARK, CustomTabColorSchemeParams.Builder().apply {
setToolbarColor(ContextCompat.getColor(app, R.color.dark_colorPrimary))
}.build())
}.build()
} }
} }

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#2e7d32</color> <color name="colorPrimary">@color/dark_colorPrimary</color>
<color name="colorPrimaryDark">#005005</color> <color name="colorPrimaryDark">#005005</color>
<color name="colorSecondary">#AEEA00</color> <color name="colorSecondary">#AEEA00</color>
<!-- This actually takes precedence over v27: https://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch --> <!-- This actually takes precedence over v27: https://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch -->

View File

@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#4CAF50</color> <color name="light_colorPrimary">#4CAF50</color>
<color name="dark_colorPrimary">#2e7d32</color>
<color name="colorPrimary">@color/light_colorPrimary</color>
<color name="colorPrimaryDark">#087f23</color> <color name="colorPrimaryDark">#087f23</color>
<color name="colorSecondary">#AEEA00</color> <color name="colorSecondary">#AEEA00</color>
<color name="navigationBarColor">@android:color/black</color> <color name="navigationBarColor">@android:color/black</color>