From 42914932561beb3cd5246fc1ffc159cbe985ea9b Mon Sep 17 00:00:00 2001 From: seven332 Date: Fri, 8 Apr 2016 19:33:13 +0800 Subject: [PATCH] Fix status bar background color above NavigationView --- .../ehviewer/widget/EhNavigationView.java | 82 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 2 +- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/hippo/ehviewer/widget/EhNavigationView.java diff --git a/app/src/main/java/com/hippo/ehviewer/widget/EhNavigationView.java b/app/src/main/java/com/hippo/ehviewer/widget/EhNavigationView.java new file mode 100644 index 000000000..8918d4bbe --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/widget/EhNavigationView.java @@ -0,0 +1,82 @@ +/* + * Copyright 2016 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.widget; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.os.Build; +import android.support.annotation.NonNull; +import android.support.design.widget.NavigationView; +import android.util.AttributeSet; + +import com.hippo.widget.drawerlayout.DrawerLayoutChild; + +public class EhNavigationView extends NavigationView implements DrawerLayoutChild { + + private static final int SCRIM_COLOR = 0x44000000; + private static final boolean DRAW_SCRIM = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; + private Paint mPaint; + private int mFitPaddingTop; + + public EhNavigationView(Context context) { + super(context); + init(); + } + + public EhNavigationView(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public EhNavigationView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + private void init() { + setWillNotDraw(false); + } + + @Override + public void draw(@NonNull Canvas canvas) { + super.draw(canvas); + + if (DRAW_SCRIM && mFitPaddingTop > 0) { + if (null == mPaint) { + mPaint = new Paint(); + mPaint.setColor(SCRIM_COLOR); + } + canvas.drawRect(0, 0, getWidth(), mFitPaddingTop, mPaint); + } + } + + @Override + public void setFitPadding(int top, int bottom) { + mFitPaddingTop = top; + } + + @Override + public int getLayoutPaddingTop() { + return 0; + } + + @Override + public int getLayoutPaddingBottom() { + return 0; + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 0b9a56868..4adceabd8 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -32,7 +32,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> -