mirror of
https://github.com/AdvDebug/Brovan
synced 2026-08-09 11:57:17 +00:00
Fix drawer header status bar inset handling
Apply system bar insets to the navigation drawer header so it no longer overlaps with the status bar.
This commit is contained in:
@@ -15,6 +15,8 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -76,10 +78,26 @@ public class MainActivity extends AppCompatActivity {
|
||||
return true;
|
||||
});
|
||||
navigation.setCheckedItem(R.id.nav_library);
|
||||
insetDrawerHeader(navigation);
|
||||
|
||||
show(R.id.nav_library);
|
||||
}
|
||||
|
||||
private void insetDrawerHeader(NavigationView navigation) {
|
||||
View header = navigation.getHeaderView(0);
|
||||
if (header == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int basePadding = header.getPaddingTop();
|
||||
ViewCompat.setOnApplyWindowInsetsListener(header, (view, insets) -> {
|
||||
int top = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top;
|
||||
view.setPadding(view.getPaddingLeft(), basePadding + top, view.getPaddingRight(),
|
||||
view.getPaddingBottom());
|
||||
return insets;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:background="@color/surface"
|
||||
android:fitsSystemWindows="true"
|
||||
app:headerLayout="@layout/nav_header"
|
||||
app:menu="@menu/nav_menu" />
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
android:background="@color/surface_variant"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:paddingTop="28dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="20dp">
|
||||
|
||||
<TextView
|
||||
|
||||
Reference in New Issue
Block a user