adjustPan not working with FLAG_LAYOUT_NO_LIMITS - android

My Requirement is a full transparent status bar with change color of the status bar in same activity dynamically.
For that, I added getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
and in style.xml
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">false</item>
So It's working fine but I need to adjust screen when soft keypad opens.
So I tried android:windowSoftInputMode="adjustPan|adjustResize" but screen not resized or scrolled. Anyone can help me on same.

Make transparent and change color dynamically like this dont set flag FLAG_LAYOUT_NO_LIMITS then check the screen when keypad is opened.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getResources()
.getColor(R.color.themeToolbarColor));
}

Related

How to make the status color to transparent in android

I am going to make the status bar as a transparent in android.
This is the screenshot same of our app status.
But I hope to make the status like this image.
Please tell me how to make the status as a transparent color.
Thanks in advance.
All you need to do is set these properties in your theme:
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
Your activity / container layout you wish to have a transparent status bar needs this property set:
android:fitsSystemWindows="true"
It is generally not possible to perform this for sure on pre-kitkat, looks like you can do it but some strange code makes it so.
EDIT: I would recommend this lib: https://github.com/jgilfelt/SystemBarTint for lots of pre-lollipop status bar color control.
Well after much deliberation I've learned that the answer to totally disabling the translucency or any color placed on the status bar and navigation bar for lollipop is to set this flag on the window
// In Activity's onCreate() for instance
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);
}
Have you tried add
<item name="android:windowTranslucentStatus">true</item>
to your AppTheme style in style.xml ?

How to change status bar color transparent and items on it to green in android?

I want to make the status bar like in the image below.
I tried a few things but none of them worked. Can some one point me to the right direction.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.colorPrimary));
}
super.onCreate(savedInstanceState);
and add this line to theme
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>

Dynamically change status bar color without losing transparency

I know I can use colorPrimary to determine the color of Toolbar, and colorPrimaryDark to determine the color of Status bar.
I'm using the following theme
<!-- Base application theme. -->
<style name="Theme.Noteplus.Base.Brown" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimaryLight</item>
<item name="colorPrimaryDark">#ff0000</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
One of the interesting attribute is, when I slide out the navigation menu, the status bar becomes transparent automatically.
During run-time, sometime I would like to change the color of status bar.
setTitle("Recycler bin");
toolbar.setBackgroundColor(Color.BLUE);
getWindow().setStatusBarColor(Color.parseColor("#5694FF"));
It will looks as follow
Unfortunately, calling setStatusBarColor, will also loss the transparency attribute of status bar, when we slide out the navigation menu.
May I know, how to change status bar color during run-time, without lossing its transparency attribute? For my case, after I changing the status bar to blue during run-time, when I slide out navigation drawer, I wish to see status bar transparency attribute being retained.
Update
I had tried
private void setStatusBarColor(int color) {
if (Build.VERSION.SDK_INT >= 21) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(color);
}
}
It doesn't help to provide transparency attribute when the navigation drawer slides out.
You are using a DrawerLayout. That means, that instead of using Window#setStatusBarColor(int) you should be using one of DrawerLayout#setStatusBarBackground() overloads.
The equivalent of your code is following:
ColorDrawable colorDrawable = new ColorDrawable(0xFF5694FF);
drawerLayout.setStatusBarBackground(colorDrawable);
I've applied minor changes to the template app that can be created with Android Studio wizard:
I guess your problem with transparency is not about the method you are using but its rather about the color itself!
You are using this getWindow().setStatusBarColor(Color.parseColor("#5694FF"));
Try to use RGBA instead of RGB so make it transparent, should be something like this:
getWindow().setStatusBarColor(Color.parseColor("#5694FF80"));
private void changeStatusBarColor(String color){
if (Build.VERSION.SDK_INT >= 21) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.parseColor(color));
}
}
If you check here in stack overflow everyone before that line of code set the transparency of the status bar to solid with
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)

Custom Translucent Color (changing transparency)

I am trying to achieve brighter translucent status bar ,only the status bar and trying to keep navigation bar as its default.
I tried some solutions(actually non of them worked as what i want).
In this one i couldn't change translucent transparency, i am trying to get brighter one.But it is not changing.
http://blog.raffaeu.com/archive/2015/04/11/android-and-the-transparent-status-bar.aspx
The other option, i tried to use fullscreen theme and placed a gradient view same height as status(that is what i want). But in this time Layout extends behind of navigation and navigation looses its black background.I couldn't find solution for that.(making it translucent not what i want)
TLDR : i am trying to get brighter translucent status with keeping navigation as its default. Is it possible?
Edit. min SDK is 20
(sorry for bad english)
Yes, it is possibile.
Set the translucent status
<style name="AppThemeTranslucent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
Set a color for your status bar using:
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setTrasparentStatusBar() {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(this, R.color.status_bar_color));
window.setNavigationBarColor(ContextCompat.getColor(this, android.R.color.black));
}
Add this property to you root layout
android:fitsSystemWindows="true"
And this is what I achieve with this code
EDIT
I investigated about this feature, not all the view implement fitsSystemWindows so not always you can get this results.
I suggest you to read this and here a repo with a sample using a CoordinatorLayout with a negative marginTop
I found the solution here
By adding this one into onCreate()
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
And this adding this into your style
<item name="android:statusBarColor">#android:color/transparent</item>

Status bar transparency doesn't work

I am trying to make status bar transparent in my application using this code:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(Color.TRANSPARENT);
But it doesn't work. Status bar just change a color and became grey, not transparent. Where is my mistake? How to make status bar transparent?
Try this in your styles.xml(v21)
<name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
Update
You can achieve the same effect programatically on KitKat and afterwards by setting this Window flag
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow(); // in Activity's onCreate() for instance
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
If you set a background resource (like a color or a picture) to your layout, you will see the color or picture "below" the status bar.
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#color/primary_dark</item>
Source

Categories

Resources