gpt4 book ai didi

android - 导航 View 在 Android 中始终可见

转载 作者:行者123 更新时间:2023-11-30 05:05:38 25 4
gpt4 key购买 nike

我想通过单击底部应用栏打开导航 View 。但导航 View 始终可见。

我的布局 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 显示导航 View 。应用程序在那里,但导航 View 始终显示。我只想用这个点击监听器显示导航 View 。我怎样才能做到这一点 ?提前致谢。

最佳答案

当您开始 Activity 时,您正在打开它。请删除 onCreate 方法中的行

drawerLayout.openDrawer(GravityCompat.START);

和改变

android:layout_gravity="end"

android:layout_gravity="start"

关于android - 导航 View 在 Android 中始终可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54643175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com