Status bar and toolbar equal to the Android chat - android

How do I make the toolbar the same as Android chat? That is white and also the status bar.

you can try ` if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow()
.setStatusBarColor(
ContextCompat.getColor(activity, color)
);
}`

Related

Change status bar color in android api level 15

i used this library:
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
private void initStatusBar() {
Window window = getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setTintColor(ContextCompat.getColor(this, R.color.colorBlack));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
window.setStatusBarColor(Color.TRANSPARENT);
}
}
This method is called in main activity before setContentView(). It's working but the status bar content items are all white, so nothing seen, I want black color status bar content text.
My min sdk version is 15 and max 26. My background is a png file. so I want the same in status bar.

Make Notification bar gradient and navigation bar black at the same time

I can create a transparent notif+nav bar and then set below the notif bar a custom view that has a gradient background. This is ok.
But how can I create a nav bar that is black, and not transparent at the same time? (So: gradient notif bar+black filled nav bar)
Is it possible?
Here is my old code
fun setTransparentNotificationBar(window: Window) {
with(window) {
addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
}
}
Thanks
OK the answer is:
with(window) {
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
statusBarColor = Color.TRANSPARENT
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
}

Change color and theme of fab button

I used custom style resource and used the following code to change the theme which changes action bar and status bar color but fab button theme doesn't change.
getTheme().applyStyle(switchValue? R.style.AppTheme1:R.style.AppTheme2 , true);
The color of Floating action button is defaulted to colorAccent you can change this from code.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
fab.setBackgroundTintList(ColorStateList
.valueOf(getResources()
.getColor(colorsArray[themeId],getTheme())));
}
the valueOf method in the above code takes color of type int
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
fab.setBackgroundTintList(ColorStateList
.valueOf(YourColorValue)));
}

How to set light status bar for Android N

I use this way to set light status bar for Android M, and it works well:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
But, it does not work at Android N. The words in status bar are still white. Is it a bug? Or is there any way to set light status bar at Android N?
Well, I found the question.It did works to set light status bar mode.But after that, i changed the status bar's color, called setSystemUiVisibility() again and set other value.So the light status bar is not valid.
Just call this method from any activity and pass color code too
public static void makeStatusBarLight(Activity activity, int color) {
Window window = activity.getWindow();
window.addFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(FLAG_TRANSLUCENT_STATUS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(color);
}
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
call like this
makeStatusBarLight(BaseActivity.this, getResources().getColor(R.color.yourcolor));

Set status bar color dynamically in android

How to set status bar color dynamically for an application, am using view pager while swiping (horizontally) status bar color and title bar and button should change the color . as per my code title and button color changing perfectly ,but the issue is status bar color taking next color from array list. how to fix that issue can anyone help me. here is my code
private int[] colors = new int[]{0xffffd200, 0xff37beb7, 0xff00ccff, 0xff8585c1, 0xfff2a03c, 0xff2a80b9, 0xfff15972,
0xffe9776c, 0xff9dcc96,0xff76c069};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = ((Activity) context).getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
int coloring = position % colors.length;
int new_color = colors[coloring];
window.setStatusBarColor(new_color);
title_bar.setBackgroundColor(new_color);
set_share.setBackgroundColor(new_color);
}
else{
int color = position % colors.length;
itemView.setBackgroundColor(colors[color]);
title_bar.setBackgroundColor(colors[color]);
set_share.setBackgroundColor(colors[color]);
}
To change status bar color use setStatusBarColor(int color). According the javadoc, we also need set some flags on the window.
Working snippet of code:
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(activity.getResources().getColor(R.color.example_color));
This is taken from following reference:
How to change status bar color to match app in Lollipop? [Android]
coming to Status bar color, you can only add it to devices with API level more than 21. To those devices which satisfy this condition you can change the StatusBar color dynamically as shown below.
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(getResources().getColor(R.color.Statusbar));
}
When I wanted to set the status bar color, I used https://github.com/jgilfelt/SystemBarTint
I used it like that :
public static void colorStatusBar(Window window, Activity activity) {
Log.v(Constants.LOG_TAG, "Start defining color bar status");
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
SystemBarTintManager tintManager = new SystemBarTintManager(activity);
tintManager.setStatusBarTintEnabled(true);
tintManager.setTintColor(activity.getResources().getColor(R.color.colorPrimaryDark));
}
}
But beware that setting status bar color is only possible if your app runs on a phone with API >= 19

Categories

Resources