apply app/system theme to WebView (#1972)

This commit is contained in:
Asiel Díaz Benítez
2021-07-15 10:46:09 -04:00
committed by GitHub
parent 623976424e
commit 4dce3734ff
2 changed files with 7 additions and 0 deletions
+1
View File
@@ -28,6 +28,7 @@ repositories {
}
dependencies {
implementation 'androidx.webkit:webkit:1.4.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.0'
@@ -15,6 +15,8 @@ import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.widget.SearchView;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
@@ -41,6 +43,10 @@ public class WebViewActivity extends PassphraseRequiredActionBarActivity
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
webView = findViewById(R.id.webview);
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(webView.getSettings(),
DynamicTheme.isDarkTheme(this) ? WebSettingsCompat.FORCE_DARK_ON : WebSettingsCompat.FORCE_DARK_OFF);
}
webView.setWebViewClient(new WebViewClient() {
// `shouldOverrideUrlLoading()` is called when the user clicks a URL,
// returning `true` means, the URL is passed to `loadUrl()`, `false` aborts loading.