12

Could anybody help me out with following image. As I have to apply gradient to status bar. I know to do only single color to status bar through them colorPimaryDark.enter image description here

As you can see in Image it shows same gradient in status bar as in verification layout.

Thanks

Bansi Doshi
  • 229
  • 1
  • 3
  • 12
  • 1
    [http://meta.stackoverflow.com/questions/266384/is-it-ok-to-downvote-questions-asking-about-how-to-achieve-something-without-ha](http://meta.stackoverflow.com/questions/266384/is-it-ok-to-downvote-questions-asking-about-how-to-achieve-something-without-ha) – M D Apr 28 '16 at 06:48
  • 1
    set status bar transparent and make the toolbar big and set the gradient . – Zahidul Islam Apr 28 '16 at 06:52
  • Theme? @ZahidulIslam – Bansi Doshi Apr 28 '16 at 07:00

1 Answers1

41

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>

The ui will be look like this .

enter image description here

Zahidul Islam
  • 3,180
  • 1
  • 25
  • 35
  • 1
    thank you for the nice answer and dedication. Is there any way only the status bar make transparent rather than transparent both status bar and navigation button on the bottom. – Dehan Wjiesekara Jun 02 '17 at 09:48
  • 4
    android:windowSoftInputMode="adjustPan" not working :( Now soft keyboard is covering the EditTexts. – User Jul 10 '17 at 10:02
  • 3
    It also makes your UI goes under the Soft navigation keys. – Ashutosh Sagar Dec 21 '18 at 11:57
  • it works but what if I don't remove the navigationbar ? because with this code , the activity content goes below the navigation bar – Navid Abutorab Dec 19 '19 at 06:02
  • @NavidAbutorab , You can't do that by keeping existing navigation bar. Because the status bar and toolbar are having different ways of representation. – Zahidul Islam Dec 20 '19 at 10:49