Панель навигации выдает панель действий скрытой, щелчок элементов навигации не работает и фон элемента изображения изменен - PullRequest
0 голосов
/ 24 апреля 2019

Я создал меню «Слайд» с панелью навигации, панель действий скрыта на основной активности, элементы не активируются, а изображения элементов навигации отображаются неправильно. прикрепление изображений и кода ниже.

Вот так это выглядит

enter image description here

Как и должно быть (в iOS)

enter image description here

добавлена ​​навигация в main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout"
    android:fitsSystemWindows="true"
    android:background="?attr/colorButtonNormal"

    tools:context=".MainActivity"
    tools:openDrawer="start">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            android:id="@+id/toolbar"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:elevation="4dp"
            />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/fragment_container"/>


    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:id="@+id/nav_view"
        app:headerLayout="@layout/nav_header"
        app:itemTextColor="@color/viewBgr"
        app:menu="@menu/drawer_menu"
        />

nav_header.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:background="@color/statusBar"
    android:gravity="bottom"
    android:padding="16dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:layout_height="100dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ABC"
        android:textColor="@color/viewBgr"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        />

</LinearLayout>

drawer_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view"
    >

    <group android:checkableBehavior="single">
        <item android:id="@+id/nav_nightmode"
            android:icon="@drawable/theme"
            android:title="Theme"/>
        <item android:id="@+id/nav_touch"
            android:icon="@drawable/fingerprint"

            android:title="Touch Id"/>
    </group>

    <item android:title="Cmmunicate">
        <menu>
            <item android:id="@+id/nav_contact"
                android:icon="@drawable/contact_us"

                android:title="Contact Us"/>
            <item android:id="@+id/nav_notification"
                android:icon="@drawable/notification"
                android:title="Notification"/>
            <item android:id="@+id/nav_userguide"
                android:icon="@drawable/user_guide"
                android:title="User Guide"/>
            <item android:id="@+id/logout"
                android:icon="@drawable/logout"
                android:title="Logout"/>

        </menu>
    </item>

</menu>

создал еще один файл styles.xml с интерфейсом v24 и добавил его в файл манифеста Android без панели действий для определенного действия

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>

MainActivity.java

Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        drawer = findViewById(R.id.drawer_layout);
        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setBackgroundColor(getResources().getColor(R.color.navigation));


        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

действие, добавленное в тот же класс, найти метод ниже

public boolean onNavigationItemSelected(@NonNull MenuItem menuItem)

1 Ответ

1 голос
/ 24 апреля 2019

Попробуйте это:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/white"
            app:popupTheme="@style/AppTheme.PopupOverlay">


           .....


        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:openDrawer="start">

        <include
            layout="@layout/app_bar_dashboard" // APP_BAR
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:headerLayout="@layout/nav_header_dashboard"
            app:itemIconTint="@drawable/drawer_item"
            app:itemTextColor="@drawable/drawer_item"
            app:menu="@menu/activity_dashboard_drawer" />
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

В соответствии с этим xml вы также должны изменить класс java.

Если это не сработает, пожалуйста, дайте мне знать в комментарии.

РЕДАКТИРОВАТЬ:

app_bar_dashboard:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="ai.gramboard.app.activity.DashboardActivity">

    <include layout="@layout/content_dashboard"/>  //include here content xml 

</FrameLayout>
...