Change the Android statusbar to a custom drawable on Lollipop devices.
by Napalm.
StatusBarView
public class StatusBarView extends View { private int mStatusBarHeight; public StatusBarView(Context context) { this(context, null); } public StatusBarView(Context context, AttributeSet attrs) { super(context, attrs); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } } @Override public WindowInsets onApplyWindowInsets(WindowInsets insets) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ mStatusBarHeight = insets.getSystemWindowInsetTop(); return insets.consumeSystemWindowInsets(); } return insets; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),mStatusBarHeight); } }
Values-v21.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="AppTheme" parent="BaseAppTheme"> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@android:color/transparent</item> </style> </resources>
activity_main.xml
<LinearLayout 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:orientation="vertical" tools:context=".MainActivity" > <com.example.StatusBarView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/top_gradient" /> <!--etc --> </LinearLayout>
top_gradient.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:type="linear" android:startColor="#ff7300" android:centerColor="#77000000" android:endColor="#000000" android:centerX="0.5" android:centerY="0.3" android:angle="0" /> </shape>
//… etc …