How to apply gradient to status bar in android?

Can anyone help me with the following image. Since I have to apply the gradient to the status bar. I know to make only one color in the status bar through them colorPimaryDark. enter image description here

As you can see in the image, it shows the same gradient in the status bar as in the check layout.

thanks

+11
source share
2 answers

Your oncreate should be like this

@Override protected void onCreate(Bundle savedInstanceState) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } 

The layout file should be like this.

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff" tools:context="sslwireless.com.testfullscreen.MainActivity"> <!--RePresent Toolbar--> <LinearLayout android:orientation="horizontal" android:background="@drawable/gradient" android:layout_width="match_parent" android:layout_height="100dp"> <ImageView android:layout_gravity="center_vertical" android:src="@drawable/ic_arrow_back_white_24dp" android:layout_marginLeft="10dp" android:layout_width="35dp" android:layout_height="35dp" /> <TextView android:layout_gravity="center_vertical" android:textSize="25sp" android:gravity="center_horizontal" android:textColor="#fff" android:text="Test Title" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </RelativeLayout> 

And the gradient file looks like this.

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:angle="135" android:startColor="#f56f2c" android:endColor="#fa9f46"/> </shape> 

ui will look like this.

enter image description here

+37
source

the accepted answer works, but if your toolbar and status are minimized. You can do it like here how to set the status bar background as gradient color or drawing in Android

0
source

All Articles