Android: Größe der Navigationsschublade
Ich habe eine Android-App mit einer Navigationsschublade. Die Schublade bezieht ihre Elemente aus einer Menüressourcendatei.
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
Über dem aktiven Element befindet sich eine halbtransparente Ebene. Dies ist das Standardmaterial. Mein Problem ist mit der Größe / dem Rand dieser Ebene.
Ich hätte gerne folgendes:
An Stelle von: https://i.stack.imgur.com/Zlp9p.png
Ich kann es nach dieser Antwort quadratisch machen , aber es hat immer noch einen kleinen Rand.
Wie kann ich das erreichen?
Antworten
Mit den itemShapeInset*Attributen können Sie den gesamten Bereich ausfüllen:
<com.google.android.material.navigation.NavigationView
app:itemShapeInsetStart="0dp"
app:itemShapeInsetEnd="0dp"
app:itemShapeAppearanceOverlay="@style/ShapeAppearanceOverlay.Nav.Square"
und die itemShapeAppearanceOverlayquadratischen Ecken zu haben:
<style name="ShapeAppearanceOverlay.Nav.Square" parent="">
<item name="cornerSize">0dp</item>
</style>
Haben Sie dieses Attribut versucht zu ändern app:itemHorizontalPadding="0dp".
Du willst das
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
style="@style/Widget.Custom.NavigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:clipToPadding="false"
android:fitsSystemWindows="true"
android:theme="@style/NavigationTheme"
app:headerLayout="@layout/nav_header_main"
app:itemHorizontalPadding="45dp"
app:itemIconPadding="@dimen/_17sdp"
app:itemIconTint="#000"
app:itemTextColor="#000"
app:menu="@menu/activity_main_drawer" />
Stile
<style name="Widget.Custom.NavigationView" parent="Widget.Design.NavigationView">
<item name="itemIconTint">?attr/colorNavigationItem</item>
<item name="itemTextColor">?attr/colorNavigationItem</item>
<item name="itemBackground">?attr/drawableNavigationItemBackground</item>
</style>
<style name="NavigationTheme" parent="AppTheme">
<item name="android:layout_marginBottom">4dp</item>
</style>
hinzufügen attr.xmlinvalues
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="colorNavigationItem" format="color" />
<attr name="colorNavigationItemSelected" format="color" />
<attr name="drawableNavigationItemBackground" format="reference" />
</resources>