我想用底部的应用栏单击打开导航视图。但是导航视图始终可见。
我的布局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
显示导航视图。应用程序去那里,但导航视图始终显示。我只想使用此点击监听器显示导航视图。我怎样才能做到这一点 ?预先感谢。
答案 0 :(得分:0)
您在开始活动时将其打开。请删除onCreate
方法中的行
drawerLayout.openDrawer(GravityCompat.START);
并更改
android:layout_gravity="end"
到
android:layout_gravity="start"