From 005fff0330780ab0457483cd84dc095033c5b3b7 Mon Sep 17 00:00:00 2001 From: Graziano Capelli Date: Sun, 16 Jun 2019 09:06:54 +0200 Subject: [PATCH] Fixes the color of the Status Bar on Android API 21+ --- app/build.gradle | 2 +- .../airdatabridge/AirDataBridgeActivity.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 22c4023..0913b7a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,7 +7,7 @@ android { minSdkVersion 14 targetSdkVersion 27 versionCode 1 - versionName "1.0.1b_20190505" + versionName "1.0.1b_20190616" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/eu/basicairdata/airdatabridge/AirDataBridgeActivity.java b/app/src/main/java/eu/basicairdata/airdatabridge/AirDataBridgeActivity.java index 959407f..107089e 100644 --- a/app/src/main/java/eu/basicairdata/airdatabridge/AirDataBridgeActivity.java +++ b/app/src/main/java/eu/basicairdata/airdatabridge/AirDataBridgeActivity.java @@ -23,6 +23,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.os.Build; import android.support.annotation.NonNull; import android.support.design.widget.TabLayout; import android.support.v4.app.ActivityCompat; @@ -38,6 +39,7 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.Window; import android.view.WindowManager; import android.widget.TextView; import android.widget.Toast; @@ -70,6 +72,16 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_airdatabridge); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Window window = this.getWindow(); + // clear FLAG_TRANSLUCENT_STATUS flag: + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + // finally change the color + window.setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); + } + final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);