How to get lollipop status bar on kitkat - android

I'm trying to achieve that Status bar with PrimaryDarkColor And PrimaryColor like Lollipop on Kitkat and here is my try:
<style name="PopularTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimaryDark">#color/colorPrimaryDarkPopular</item>
<item name="colorPrimary">#color/ColorPrimaryPopular</item>
<!--here is what I've added to try to get transparency -->
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
Also, I test this method with https://github.com/jgilfelt/SystemBarTint but it won't be my choice because I'm using another color for each activity.
How to achieve that status bar with PrimaryDarkColor and PrimaryColor in Kitkat?
Result:

I've just checked here on the app I work at how we do it.
First remove everything from under <!--here is what I've added to try to get transparency -->, we have nothing of those on our style. However it works the AppCompat theme or activity already does for you.
and then you add the extra rule for Kitkat:
#TargetApi(Build.VERSION_CODES.KITKAT)
private static void setupWindowKiKat(Window window) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
and call it from your activity:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
setupWindowKiKat(getWindow());
it is possible that you can add this to a values-v19\style.xml but above it's how it's on our app. Hope it helps.

You Should first root Your device, then go to Google play store and install (Wanam Xposed) http://repo.xposed.info/module/ma.wanam.xposed
open it and follow some steps right there then install (Xposed installer) http://repo.xposed.info/module/de.robv.android.xposed.installer
Then open this last Go to "download" and look for "Flat style colored bars" download and install it then go back to Modules activate it and reboot your phone and You will see the changes.
I hope i helped. i works great for me on ace 4 Sm-g316hu

This is not possible because they both run on a different API (lollipop on 20, 21 or 22).

Related

Android: windowLightNavigationBar not working

Background: My background is in web development, ruby and javascript. I'm working on a mostly react-native app, so very likely I'm missing something basic.
What I want
android navigation bar to be white with dark system buttons see image in link white navigation bar
My Current Code
res/values/style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:navigationBarColor">#FFFFFF</item>
</style>
</resources>
What is happening instead
The background AND the buttons are white. which is not so great for UX.
** What I have Tried **
this is what got me where I am now Change navigation bar icon color on Android
I have tried putting style.xml in a values-v27 folder.
I just worked on this same topic and found out you need to run at least Android 9.0 (or API level 28) on the device/emulator for this to work.
Also, I had to add this to the color of the bar:
<item name="android:navigationBarColor">#android:color/white</item>
So, recommended steps:
Create a values-v28 folder
Insert the style:
<item name="android:navigationBarColor">#android:color/white</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightNavigationBar">true</item>
In your other values folder, you kind of have to live with the fact that this windowsLightNavigationBar doesn't apply...
Small remark
I also found a bug on this change, when putting app in background and then opening it again, the navbar buttons stay white for a second before getting the dark color
Your code is working as intended for me. Make sure you have the file name and file path written correctly:
https://imgur.com/xclYDuZ
A new approach would be:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.navigationBarColor = ContextCompat.getColor(this, android.R.color.white)
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightNavigationBars = true
}

Change status bar color XML

I have defined
<item name="android:statusBarColor">#color/some_color</item>
<item name="android:navigationBarColor">#color/some_color2</item>
and it works well in emulator with API 22 but in my Huawei with the same Android version status bar and navigation bar color not works. It remains the same like before.
I can add that another attributes like android:textApperance or android:background works fine there is a problem just with those two.
Place this is your values/styles.xml
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/my_awesome_color</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/my_awesome_darker_color</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight & colorSwitchThumbNormal. -->
</style>
and set this theme to your Activity in manifist
like this
<activity
android:name=".MainHomeFragmentActivity"
android:theme="#style/MyMaterialTheme" />
Huawei has not implemented in EMUI 3.1 based on Lollipop 5.1.1 which have colors of status bar. So there are 2 ways to solve it.
1-)
The files you need:
[emui3.1.png https://drive.google.com/file/d/0BwQ4XeikVQ3kU2ZNVW53UFQ4WDQ/view?usp=sharing]
[emui3.1bg.png https://drive.google.com/file/d/0BwQ4XeikVQ3kVnh5UTBrS3F4aW8/view?usp=sharing]
This is an EMUI theme from EMUI offical BBS(this theme works well but without Translucent Status Bars): https://drive.google.com/file/d/0BwQ4XeikVQ3kRmdSZ19LblpiQ00/view?usp=sharing
HUAWEI LAUNCHER
Download any Huawei theme and get .hwt file.
Use any unzip sofaware and unzip it.
Put emui3.1bg.png into it(I think you will now how to do it.), then zip again, make sure it likes before(Well, added a photo...), change its name to XXX.hwt
Put the new .hwt into (NOT SDCARD1) /sdcard/HWThemes(if there is not it, you must create one)
Open THEMES APP on your EMUI phone and change to the theme you changed before.
Open emui3.1.png with system library, and set it to the launcher wallpaper.
It maybe works, if not, do 1-6 again.
Here is a tutorial: https://www.youtube.com/watch?v=HTweBQgjXr8
2-) You need to root your device. You can check here to root : https://www.kingoapp.com/root-huawei.htm
then [https://drive.google.com/file/d/0BwQ4XeikVQ3kZGJDMWpuSGF0bDA/view?usp=sharing] just flash this zip

How to create a fully transparent Navigation Bar?

I want to change the Navigation Bar fully transparent like on the picture below.
I tried <item name="android:windowTranslucentNavigation">true</item> but it is not fully transparent (more like 50%).
Is there a solution? Because i found nothing to it, but I saw some apps that used it like Nova. And its even in googles guidelines https://material.google.com/layout/structure.html#structure-system-bars
I was inspired by Google Keep app, which have similar implementation like shown below:
So i tried to find a proper post on how to achieve this thing but unfortunately found nothing and also above answers weren't working. So i decided to try out all the flags related to navigationBar Android Studio was suggesting.
Let me explain in detail:
Only android:navigationBarColor won't do any thing when you are using a light theme. But on dark theme, it will work.
Setting windowTranslucentNavigation to true will do 2 things:
draw the activity below the soft navbar
override navigationBarColor and force it to be transparent.
Which will look like below image:
If you use FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS (follow #Frankenxtein's answer) you will get below result:
Which is somehow close to desired result, but it isn't because it draws activity components below navbar. And also it mess your padding and margin (see full screenshot here). And more, you have to do it for each activity and also have to adjust current margin.
The Solution
This can be achieved without compromising current layout. To do this in Dark theme, you have no issue, just setting android:navigationBarColor will do the work.
However our goal here is to do it with a light theme let (#FFFFFF). Using android:windowLightNavigationBar which requires API 27 or higher along with android:navigationBarColor will result what we want.
<item name="android:navigationBarColor">#color/colorPrimaryDark</item>
<item name="android:windowLightNavigationBar">true</item>
Here for my app case colorPrimaryDark is #FFFFFF in light theme and dracula in dark theme, you can also declare a new variable for this. Which yields below results:
Light Theme
Dark Theme
Here android:navigationBarColor is setting background colour of navbar. And android:windowLightNavigationBar setting dark button colours and indicates that background is light as you can understand from it's name.
Hope this helps !
use following code in onCreate of your Activity:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
and in your styles.xml:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">false</item>
Since no one has mentioned this and I spent too much time trying to figure it out on my own. A solution for API 29+ to make the system bars fully transparent regardless of anything:
<item name="android:enforceNavigationBarContrast">false</item>
<item name="android:enforceStatusBarContrast">false</item>
You can achieve that using FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS. Documentation explains:
Flag indicating that this Window is responsible for drawing the
background for the system bars. If set, the system bars are drawn with
a transparent background and the corresponding areas in this window
are filled with the colors specified in getStatusBarColor() and
getNavigationBarColor().
Set it like that in your Activity's onCreate:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
Try this
<resources>
<style name="Theme" parent="android:Theme.Material.Wallpaper.NoTitleBar">
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
It worked for android >= 10
You can try the color by default color android
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:windowTranslucentNavigation">true</item>
By the way you can try this
<item name="android:fitsSystemWindows">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>

Actionbar Issue

I want custome actionbar so i edited values-v14/style.xml
Here is what i change in xml file
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<item name="android:height">60dp</item>
</style>
this is my java code where i enabled drawer icon
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayShowTitleEnabled(true);
Now I run on 4.2 and Up device its fine But when i run 4.1 device it's show back icon not drawer icon any answer must be appreciated.
you can see drawer icon replaced with back
Hear is image of 4.4.4 Device you can check and please help me
In your style.xml
<style name="Theme.mytheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">#drawable/your_icon</item>
</style>
add any icon you want. Icon mostly depends on Device API level.
Your ask is not clear, however... if i understand, you have an application that runs well on 4.2 devices showing drawer icon on left side (drawer menu navigation i suppose). The same application on 4.1 devices doesn't show drawer icon but back icon.
Be sure that your style.xml is correct.
Note that values-v11/style.xml is for API 11+
For API 14+ you must use values-v14/style.xml is for API 14+
You can try to add a new folder to your project values-v19/style.xml for API 19+ Android 4.4
Look in Android Official API Guides -> App Resources -> Style for more details.
And as last I give you two links resources:
To create ActionBars: http://jgilfelt.github.com/android-actionbarstylegenerator/
Useful tools can be found here: http://romannurik.github.io/AndroidAssetStudio/index.html

Using support action bar home enabled

I've just modified our code to use the new SupportActionBar provided in the v7-appcompat library but when running the code on a Jellybean phone (presumably the same problem exists for Honeycomb and Ice Cream Sandwich) the home button doesn't ever seem to be activated.
Calling getSupportActionBar().setHomeButtonEnabled(true); doesn't seem to do what it says but works for Gingerbread phones.
If I replace it with getActionBar().setHomeButtonEnabled(true) it does work.
The theme that I use for v11+ is as follows:
<style name="MyTheme" parent="#style/Theme.AppCompat">
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
<item name="android:listViewStyle">#style/MyListView</item>
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden</item>
<item name="android:buttonStyle">#style/MyButton</item>
<item name="android:radioButtonStyle">#style/MyRadioButtonStyle</item>
<item name="android:windowContentOverlay">#drawable/ab_solid_dove_grey</item>
<item name="android:windowTitleSize">#dimen/action_bar_height</item>
<item name="android:selectableItemBackground">#drawable/sel_standard_item</item>
<item name="android:windowBackground">#drawable/default_bg</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarText</item>
<item name="android:actionMenuTextColor">#color/gallery</item>
<item name="android:tabWidgetStyle">#style/MyTabWidget</item>
</style>
And the action bar style v11+ is defined:
<style name="MyActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">useLogo|showHome|showCustom</item>
<item name="displayOptions">useLogo|showHome|showCustom</item>
<item name="android:actionBarSize">#dimen/action_bar_height</item>
<item name="android:icon">#drawable/ic_launcher</item>
<item name="android:background">#android:color/transparent</item> <!-- Remove blue line from bottom of action bar -->
</style>
Anyone know why the home button is not getting enabled when on an Android version that supports action bar correctly.
=== UPDATE ===
I've just looked at the source code for the appcompat library and I've noticed the following in ActionBarImplBase which looks wrong to me:
setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);
This means that the home button will only be enabled if the Android version is less than ICS or if I've enabled the up indicator? - which I don't want.
This one worked for me:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_your_activity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// ... other stuff
}
#Override
public boolean onSupportNavigateUp(){
finish();
// or call onBackPressed()
return true;
}
The method onSupportNavigateUp() is called when you use the back button in the SupportActionBar.
Have you tried using all three of these (also try swapping for getSupportActionbar())?
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
Have you tried handling the button manually?
#Override
public boolean onOptionsItemSelected(int featureId, MenuItem item) {
int itemId = item.getItemId();
if(itemId == android.R.id.home){
// Do stuff
}
return true;
}
Try use Sherlock library for android devices such as Gingerbread cos android action bars is only supported from 3.0 upwards so the sherlock lock library gives you backward compatibility.
http://actionbarsherlock.com/ --- download library here.
Then add this lines in your code.
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(android.R.color.transparent);
actionBar.setDisplayUseLogoEnabled(false);
This would help you to add a back home key in your action bar. It would also make your icon invisible if you dont want it to show.
But if you want your app icon show on all activity simply comment this line below
actionBar.setIcon(android.R.color.transparent);
Now Please try this. Cause I was able to solve my own problem like this though it was on Sherlock. From your styles above I can see you did some customization to your themes. In my case I did some customization to my Sherlock theme and this was what gave me problem cos on android 4.0 and above my theme failed. so I simple added a piece of code that tells android to use the default Sherlock theme when it is running on android 4.0 and greater. So I suppose this would work for you. you tell android to use the default theme of v7-appcompat library on the version of android that is not working for you.
Code is below:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
this.setTheme(R.style.Theme_Sherlock);
} else {
this.setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);
}
In your case edit the theme to v7-appcompat library.
Please Mark as answer if it work for you. I believe it might be possible to customize the theme from the code for places were you are using this.
You can add an ActionBar to your activity when running on API level 7 or higher by extending ActionBarActivity class for your activity and setting the activity theme to Theme.AppCompat or a similar theme.

Categories

Resources