Here is my activity xml file with one drawerlayout. how can i add second drawer with same gravity, i mean two drawer layout with same gravity android:layout_gravity="end",
i have requirement to show one more view with slide animation.
<androidx.drawerlayout.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
</LinearLayout>
<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" >
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview_filter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
/>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
Related
My screen doesn't show the android home buttons and I'm running Android 7.0. I see a grey rectangle in the bottom, the height of where the buttons would be:
activity_payment.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
tools:context=".ui.activities.PaymentActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/status_bar_height"
android:orientation="vertical">
</androidx.constraintlayout.widget.ConstraintLayout>
<include
android:id="#+id/navigation_layout"
layout="#layout/navigation_layout" />
</androidx.drawerlayout.widget.DrawerLayout>
I tried android:elevation="10dp" and android:translationZ="10dp":
navigation_layout.xml:
<com.google.android.material.navigation.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:elevation="10dp"
app:headerLayout="#layout/nav_header_main"
app:itemIconTint="#drawable/drawer_selector"
app:itemTextColor="#drawable/drawer_selector"
app:menu="#menu/navigation_drawer">
</com.google.android.material.navigation.NavigationView>
nav_header.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/nav_header"
android:layout_width="match_parent"
android:layout_height="#dimen/nav_header_height"
android:orientation="vertical">
<ImageView
android:id="#+id/drawer_company_logo"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:gravity="start"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:scaleType="fitStart"
android:layout_gravity="start"
android:paddingBottom="#dimen/padding_small"
app:srcCompat="?brandingLogo" />
</LinearLayout>
DrawerLayout
CoordinatorLayout
AppBarLayout
...
NavigationView
Try using it like this.
or try this
Grey bar appears on navigation drawer
I am trying to add nested scroll view in my drawer layout but the nested scroll view is not working i.e. my view is not scrolling down. My content main lahout is supposed to be a scrolling layout. My layout contains a linear layout for toolbar and the content main for the home screen and a navigation view . Any type of help will be grateful. Here's my XML file code:
<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"
tools:context=".Activities.MainActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">
<include
layout="#layout/drawer_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
layout="#layout/content_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/drawer_menu">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
set NestedScrollView height to match_parent
I'm trying to add navigation drawer to this layout. It currently has a Bottom Navigation View and a relative layout to hold fragment.
Problem is I can't make the root layout a Drawer Layout coz it opts out the fragment container relative layout.
<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"
tools:context="deb.com.firebasedemo.HomePage"
>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:background="#054ec5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemIconTint="#drawable/nav_state_color"
app:itemTextColor="#drawable/nav_state_color"
app:menu="#menu/bottom_nav_menu"
android:layout_alignParentBottom="true"
>
</android.support.design.widget.BottomNavigationView>
<RelativeLayout
android:id="#+id/home_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_navigation">
</RelativeLayout>
</RelativeLayout>
I tried something like this. Putting drawer layout inside the relative layout and navigation view.
<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"
tools:context="deb.com.firebasedemo.HomePage"
>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#menu/navigation_menu"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:background="#054ec5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemIconTint="#drawable/nav_state_color"
app:itemTextColor="#drawable/nav_state_color"
app:menu="#menu/bottom_nav_menu"
android:layout_alignParentBottom="true"
>
</android.support.design.widget.BottomNavigationView>
<RelativeLayout
android:id="#+id/home_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_navigation">
</RelativeLayout>
</RelativeLayout>
But it's not working :( .. The navigation drawer won't show up.
I need some help here.
I'm using both NavigationDrawer and BottomNavigationView. But after the add Navigation Drawer, position of Bottom Navigation is changed. How do I solve that? I assume this problem is caused by my xml files.
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context="com.example.yunus.ototakip.MainActivity">
<include
layout="#layout/app_bar_navigation_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"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_navigation_bar"
app:menu="#menu/activity_navigation_bar_drawer" />
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#color/beyaz"
app:itemTextColor="#color/beyaz"
app:menu="#menu/bottombar_menu" />
Attach your BottomNavigationView inside the CoordinatorLayout (or whatever view group you've inside app_bar_navigation_bar layout) not DrawerLayout and add appropriate gravity tag.
android:layout_gravity="bottom"
Try using either of the two=
android:layout_gravity="bottom"
or
android:gravity="bottom"
use android:layout_gravity="bottom" instead of layout_alignParentBottom as it is for RelativeLayout not android.support.v4.widget.DrawerLayout.
I have a relative layout in which i have two child .one is drawer layout and the other is a frame layout in which i have used a fragment .The problem is when i keep drawer layout in the top and the frame layout in the bottom,drawer layout doesn't work and if do the opposite,frame layout doesn't
this is my relative layout
<RelativeLayout xmlns:android "http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar_actionbar"
layout="#layout/mtoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar_actionbar">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.rohit.newmastervocab.FloatingFragment"
android:id="#+id/fragment2"
android:layout_alignParentStart="true"
tools:layout="#layout/fragmentfloating"
android:layout_alignTop="#+id/drawer"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
<android.support.v4.widget.DrawerLayout android:id="#+id/drawer1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_below="#+id/toolbar_actionbar"
android:layout_alignParentBottom="true">
<ListView
android:id="#+id/drawerlist1"
android:layout_width="240dp"
android:layout_height="match_parent"
android:entries="#array/navigation_items"
android:background="#F3F6C8"
android:layout_gravity="start">
</ListView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
Mike M. is absolutely right: you need to keep FrameLayout as one of the Children of DrawerLayout.
I've updated your XML a bit, take a look:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<FrameLayout
android:layout_below="#+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_gravity="center_horizontal|bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.rohit.newmastervocab.FloatingFragment"
android:id="#+id/fragment2"/>
</FrameLayout>
</RelativeLayout>
<ListView
android:id="#+id/drawerlist1"
android:layout_width="240dp"
android:layout_height="match_parent"
android:entries="#array/navigation_items"
android:background="#F3F6C8"
android:fitsSystemWindows="true"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
Now drawer works just as expected and Fragment is stick to the bottom|center of the screen.