навигационный ящик получит новый макет - PullRequest
1 голос
/ 22 января 2020

Я пытаюсь создать свой навигационный ящик, как показано в описании material.io , т.е.

this

My текущая реализация взята из более старых спецификаций и выглядит ужасно старой, особенно мне не хватает:

  1. делитель после заголовка
  2. Наложение на выбранный элемент и c.

Activity_main. xml

<androidx.drawerlayout.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <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" >
    </com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>

и nav_header_main

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/navheader"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_header_height"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.DayNight">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:contentDescription="TODO"
        android:paddingTop="@dimen/activity_horizontal_margin"
        android:src="@mipmap/ic_launcher_round" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingStart="8dp"
        android:text="@string/app_name"
        android:layout_alignBottom="@id/navheader"
        android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6" />

</LinearLayout>

, который выглядит как: old nav

У кого-нибудь есть файл макета, чтобы получить новый внешний вид? Заранее спасибо.

1 Ответ

0 голосов
/ 22 января 2020
implementation 'com.google.android.material:material:1.2.0-alpha04'

style. xml

убедитесь, что вы используете Theme.MaterialComponents в качестве родителя

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your ThemeAdapter here. -->
        <item name="colorPrimary">@color/colorPrimaryred</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDarkred</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>

надеюсь, это поможет ...

...