Вид навигации всегда отображается в Android

Я хочу открыть навигационный вид, щелкнув нижнюю панель приложения. Но вид навигации всегда виден.

Мой макет xml:

<?xml version = "1.0" encoding = "utf-8"?>
<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:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:id = "@+id/drawer_layout"
    android:theme = "@style/ThemeOverlay.MaterialComponents.Light"
    >


    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        >


    <RelativeLayout
        android:id = "@+id/relativeLayout2"
        android:layout_width = "match_parent"
        android:layout_height = "132dp"
        android:background = "@drawable/login_bg2_gradient"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width = "match_parent"
            android:layout_height = "match_parent">


            <ImageView
                android:id = "@+id/imageView5"
                android:layout_width = "45dp"
                android:layout_height = "44dp"
                android:layout_alignParentStart = "true"
                android:layout_alignParentEnd = "true"
                android:layout_alignParentBottom = "true"
                android:layout_marginStart = "8dp"
                android:layout_marginTop = "24dp"
                android:layout_marginEnd = "8dp"
                app:layout_constraintBottom_toTopOf = "@+id/textView"
                app:layout_constraintEnd_toEndOf = "parent"
                app:layout_constraintStart_toStartOf = "parent"
                app:layout_constraintTop_toTopOf = "parent"
                app:layout_constraintVertical_chainStyle = "spread_inside"
                app:srcCompat = "@drawable/logo" />

            <TextView
                android:id = "@+id/textView"
                android:layout_width = "91dp"
                android:layout_height = "23dp"
                android:layout_alignParentStart = "true"
                android:layout_alignParentEnd = "true"
                android:layout_alignParentBottom = "true"
                android:layout_marginStart = "8dp"
                android:layout_marginEnd = "8dp"
                android:text = "SAMET DAĞ"
                app:layout_constraintBottom_toTopOf = "@+id/textView7"
                app:layout_constraintEnd_toEndOf = "parent"
                app:layout_constraintStart_toStartOf = "parent"
                app:layout_constraintTop_toBottomOf = "@+id/imageView5" />

            <TextView
                android:id = "@+id/textView7"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:layout_alignParentStart = "true"
                android:layout_alignParentEnd = "true"
                android:layout_alignParentBottom = "true"
                android:layout_marginStart = "8dp"
                android:layout_marginEnd = "8dp"
                android:layout_marginBottom = "22dp"
                android:text = "8 Şubat 2019 11:05"
                app:layout_constraintBottom_toBottomOf = "parent"
                app:layout_constraintEnd_toEndOf = "parent"
                app:layout_constraintStart_toStartOf = "parent"
                app:layout_constraintTop_toBottomOf = "@+id/textView" />

            <TextView
                android:id = "@+id/textView8"
                android:layout_width = "69dp"
                android:layout_height = "wrap_content"
                android:layout_alignParentStart = "true"
                android:layout_marginStart = "4dp"
                android:layout_marginTop = "8dp"
                android:layout_marginBottom = "8dp"
                android:text = "MOSTA"
                app:layout_constraintBottom_toBottomOf = "parent"
                app:layout_constraintStart_toStartOf = "parent"
                app:layout_constraintTop_toTopOf = "parent"
                app:layout_constraintVertical_bias = "0.0" />

            <ImageView
                android:id = "@+id/imageView6"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:layout_alignParentStart = "true"
                android:layout_alignParentTop = "true"
                android:layout_alignParentEnd = "true"
                android:layout_marginStart = "8dp"
                android:layout_marginTop = "8dp"
                android:layout_marginEnd = "8dp"
                android:layout_marginBottom = "100dp"
                app:layout_constraintBottom_toBottomOf = "parent"
                app:layout_constraintEnd_toEndOf = "parent"
                app:layout_constraintHorizontal_bias = "0.972"
                app:layout_constraintStart_toEndOf = "@+id/textView8"
                app:layout_constraintTop_toTopOf = "parent"
                app:srcCompat = "@drawable/ic_menu_manage" />


        </androidx.constraintlayout.widget.ConstraintLayout>

    </RelativeLayout>


        <com.google.android.material.navigation.NavigationView
            android:id = "@+id/nav_view"
            android:layout_width = "wrap_content"
            android:layout_height = "match_parent"
            android:layout_gravity = "end"
            android:fitsSystemWindows = "true"
            app:layout_constraintEnd_toEndOf = "parent"
            app:menu = "@menu/profile_side_menu" />

        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:id = "@+id/coordinatorlayout"
            android:layout_width = "0dp"
            android:layout_height = "89dp"
            app:layout_constraintBottom_toBottomOf = "parent"
            app:layout_constraintEnd_toEndOf = "parent"
            app:layout_constraintHorizontal_bias = "1.0"
            app:layout_constraintStart_toStartOf = "parent"
            app:layout_constraintTop_toBottomOf = "@+id/nav_view"
            app:layout_constraintVertical_bias = "0.938">

            <com.google.android.material.bottomappbar.BottomAppBar
                android:id = "@+id/bottombar"
                android:layout_width = "match_parent"
                android:layout_height = "wrap_content"
                android:layout_gravity = "bottom"
                android:backgroundTint = "#949494"
                app:buttonGravity = "bottom|top"
                app:fabAlignmentMode = "center"
                app:navigationIcon = "@drawable/ic_menu_black_24dp"
                tools:layout_editor_absoluteX = "0dp"
                tools:layout_editor_absoluteY = "606dp"

                />

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id = "@+id/bottom_float_button"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:background = "@drawable/shift_change"
                android:src = "@drawable/shift_change"
                app:backgroundTint = "@android:color/darker_gray"
                app:fabCustomSize = "50dp"
                app:layout_anchor = "@+id/bottombar"
                app:layout_constraintBottom_toTopOf = "@id/bottombar"
                app:layout_constraintTop_toBottomOf = "@+id/bottombar" />

        </androidx.coordinatorlayout.widget.CoordinatorLayout>


    </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.drawerlayout.widget.DrawerLayout>

Мой Java-код:

package com.stawiz;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.GravityCompat;
import androidx.core.view.ViewCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import android.system.Os;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationView;
import com.mxn.soul.flowingdrawer_core.ElasticDrawer;
import com.mxn.soul.flowingdrawer_core.FlowingDrawer;

import java.util.ArrayList;
import java.util.List;

public class MainMenu extends AppCompatActivity {

    FloatingActionButton floatingActionButton;
    BottomAppBar bottomAppBar;

    CoordinatorLayout coordinatorLayout;

    DrawerLayout drawerLayout;

    Button btnLogOut,btnEditProfile;

    NavigationView navigationView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_menu);

        floatingActionButton = findViewById(R.id.bottom_float_button);

        bottomAppBar = findViewById(R.id.bottombar);

        coordinatorLayout=findViewById(R.id.coordinatorlayout);

        drawerLayout=findViewById(R.id.drawer_layout);

        navigationView  = findViewById(R.id.nav_view);


        setSupportActionBar(bottomAppBar);

       bottomAppBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { // It working when profile button pressed.
            @Override
            public boolean onMenuItemClick(MenuItem item) {

                Log.e("asdas","--asdasd");



                if (drawerLayout.isDrawerVisible(Gravity.RIGHT)){
                    Log.e("right","right");
                }
                if (drawerLayout.isDrawerVisible(Gravity.LEFT)){
                    Log.e("LEFT","LEFT");
                }
                if (drawerLayout.isDrawerVisible(GravityCompat.START)){
                    Log.e("START","START");
                }
                if (drawerLayout.isDrawerVisible(GravityCompat.END)){
                    Log.e("END","END");
                }


                return true;
            }
        });

     bottomAppBar.setNavigationOnClickListener(new View.OnClickListener() {//It working when menu button pressed.
         @Override
         public void onClick(View v) {

             BottomNavigationDrawer bottomNavigationDrawer = new BottomNavigationDrawer();

             bottomNavigationDrawer.show(getSupportFragmentManager(),bottomNavigationDrawer.getTag());
         }
     });



    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.bottom_app_bar_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }



    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

      /*  switch (item.getItemId()){

            case

        }*/


        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {

        if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
            finish();
        } else {
            super.onBackPressed();
        }


    }


}

Я хочу показать навигацию с помощью bottomAppBar.setOnMenuItemClickListener. Приложение идет туда, но всегда отображается вид навигации. Я просто хочу показать навигационный вид с помощью этого прослушивателя кликов. Как я могу это сделать ? Заранее спасибо.

Это navigation_view в Activity и nav_view в XML, оба разные?

Kishore Jethava 12.02.2019 06:23

Ты прав . Я изменил это. Но похоже дело не в этом. Тем не менее вид навигации появляется всегда.

asda asda 12.02.2019 06:29
1
2
743
1

Ответы 1

Вы открываете его, когда начинаете деятельность. Пожалуйста, удалите строку в методе onCreate

drawerLayout.openDrawer(GravityCompat.START);

и изменить

android:layout_gravity = "end"

к

android:layout_gravity = "start"

Сэр, извините, я не упомянул, что мне нужен навигационный вид RTL. Поэтому я использовал конец или право. Я не использовал фреймлейаут. Может проблема в этом?

asda asda 12.02.2019 06:38

Это действительно сработало. Я поместил все содержимое, кроме представления навигации, во Framelayout, затем навигация после этого работала так, как я ожидал. Спасибо за помощь.

asda asda 12.02.2019 06:44

Другие вопросы по теме

Похожие вопросы

Просмотр местоположения на карте Google с отправкой широты и долготы
Как программно изменить атрибут представления из представления в моем recyclerView в моем фрагменте?
Ошибка Gradle после обновления до AndoidX последнего плагина Android Gradle
Android alertdialog, как предотвратить отрицательную кнопку, подтвердить действие после того, как я выбрал элемент из элементов с одним выбором
Не удается найти архитектуру apk при запуске команды «ionic cordova run android»
Автоматически нажимать кнопку отправки и как пройти ограничение по времени на кнопку отправки?
Как мне вызвать более одной функции для каждого случая при использовании оператора «когда» в Котлине?
Как обновлять фрагмент вкладки Android каждый интервал?
Событие Socket IO запускается несколько раз NodeJS
Когда мое приложение уничтожено, firebase не сохраняет моего пользователя и пропускает страницу входа в систему