From 4fa8959f1146cff5c64d33cd859378d3072c58c7 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 21 Dec 2022 15:12:44 +0100 Subject: [PATCH] Fix issue #663 - Support nav & status bar colors for Android 5 --- .../app/fedilab/android/activities/BaseActivity.java | 11 ++++++++--- .../fedilab/android/activities/BaseBarActivity.java | 9 +++++++++ .../android/activities/BaseTransparentActivity.java | 9 +++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/BaseActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseActivity.java index 2f2b870f..5070af57 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseActivity.java @@ -19,8 +19,11 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; +import android.view.Window; +import android.view.WindowManager; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -32,7 +35,6 @@ import com.vanniktech.emoji.one.EmojiOneProvider; import app.fedilab.android.R; import app.fedilab.android.helper.Helper; -import app.fedilab.android.helper.ThemeHelper; @SuppressLint("Registered") @@ -125,8 +127,11 @@ public class BaseActivity extends AppCompatActivity { } } super.onCreate(savedInstanceState); - if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) { - ThemeHelper.adjustFontScale(this, getResources().getConfiguration()); + if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + Window window = getWindow(); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(Color.BLACK); + window.setNavigationBarColor(Color.BLACK); } Helper.setLocale(this); } diff --git a/app/src/main/java/app/fedilab/android/activities/BaseBarActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseBarActivity.java index e8f0111e..156d81b8 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseBarActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseBarActivity.java @@ -19,8 +19,11 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; +import android.view.Window; +import android.view.WindowManager; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -111,6 +114,12 @@ public class BaseBarActivity extends AppCompatActivity { } } super.onCreate(savedInstanceState); + if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + Window window = getWindow(); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(Color.BLACK); + window.setNavigationBarColor(Color.BLACK); + } if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) { ThemeHelper.adjustFontScale(this, getResources().getConfiguration()); } diff --git a/app/src/main/java/app/fedilab/android/activities/BaseTransparentActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseTransparentActivity.java index 77f2df73..6b1c46f5 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseTransparentActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseTransparentActivity.java @@ -19,8 +19,11 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; +import android.view.Window; +import android.view.WindowManager; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -111,6 +114,12 @@ public class BaseTransparentActivity extends AppCompatActivity { } } super.onCreate(savedInstanceState); + if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + Window window = getWindow(); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(Color.BLACK); + window.setNavigationBarColor(Color.BLACK); + } if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) { ThemeHelper.adjustFontScale(this, getResources().getConfiguration()); }