Different color in navigation drawer - android

I have used two color: light color #607D8B for app bar and dark color #455A64 for above appbar. But problem is, navigation drawer display two different color other then I mentioned. I don't know why the different color come to the navigation drawer. So, what can be done to solve this issue ?
content_main.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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="80dp"
android:background="#455A64"
android:fitsSystemWindows="true"
app:menu="#menu/activity_main_drawer">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<ExpandableListView
android:id="#+id/ex_list_items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:childDivider="#00000000"
android:divider="#null"
android:groupIndicator="#null" />
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

Related

Grey rectangle shown on drawer NavigationView when hiding android home buttons

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

Why my colored icon doesn't show in navigation drawer

I am making an Android app. I have used the side navigation drawer in it, I have not seen the color icons in the drawer, but i used color icons
My XML code is:
<?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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/background_pic"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.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"
app:iconTint="#null"
app:menu="#menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
Use:
navigationView.setItemIconTintList(null)
or in your layout use app:itemIconTint instead of app:iconTint
<com.google.android.material.navigation.NavigationView
app:itemIconTint="#null"
error in
app:iconTint="#null"
Use the color name/code you want to use
use it
app:itemIconTint="#null"
if you are using SVG
DrawableCompat.setTint(
DrawableCompat.wrap(myImageView.getDrawable()),
ContextCompat.getColor(context, R.color.another_nice_color)
);
Change the color of drawable asset programmatically

main Layout Overlaps with Navigation Drawer

i am new with navigation drawer. I want to Create layout for my mainactivity, but why overlap so my main layout not visible, may you help me. Thanks for answer
This is my activity_main.xml layout :
<?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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
android:background="#drawable/splashscreen">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jaakkk"
android:textColor="#ffffff" />
</FrameLayout>
<include
layout="#layout/app_bar_main"
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_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
How can I do to change that?
So, your problem is drawer layout overlapping the linear layout below. Use
u can add this line in
<android.support.design.widget.NavigationView
android:layout_below="#id/drawer_layout"/>

Fixed navigation header in navigation drawer while scrolling through items

CURRENT STATE: NavigationDrawer with a NavigationHeader and NavigationMenu items. The items are large in number so scrolling is required in order to access the items towards the bottom.
REQUIREMENT: When scrolling down to the bottom, the NavigationHeader should stay fixed
Here's my activity_main layout file
<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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
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"
android:background="#00000000"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"
/>
</android.support.v4.widget.DrawerLayout>
Here's my navigation_header_main layout file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:background="#3d3b3b"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="#drawable/categories"
android:padding="1dp"
/>
</RelativeLayout>
P.S I am new to android dev. Please ask for more resources if required
Found a workaround. Definitely not the most efficient one. Please suggest if anything could be done from here.
<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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
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"
android:background="#00000000"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer">
<include layout="#layout/nav_header_main"
<android.support.design.widget.NavigationView>
Definitely works. But the header layout is redundant
I know its too old question but i sharing a solution that's working for me:
1. PLACE nav_header_main inside NavigationView
<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:menu="#menu/activity_main_drawer" >
<include layout="#layout/nav_header_main"/>
</android.support.design.widget.NavigationView>
2. ADD some empty item as suitable for your header height in #menu/activity_main_drawer file
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:enabled="false"
android:title=" " />
<item android:enabled="false"
android:title=" " />
<group android:checkableBehavior="single">
<item
android:id="#+id/home"
android:title="#string/home" />
......
</group>
</menu>
Hey guys I've come up with a solution for the nav_drawer and how we can implement the static nav_drawer without writing any extra coding.
I'm sharing git link of the project that I'm currently working on.
Thanks !!
Below is the activity_main.xml file and I've used Navigation View Menu
<?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:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_main_bg_shape"
android:orientation="vertical">
<Button
android:id="#+id/whats_cool"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="260dp"
android:layout_marginTop="400dp"
android:background="#drawable/buttonshape"
android:fontFamily="#font/delius_unicase"
android:shadowColor="#362802"
android:shadowDx="4"
android:shadowDy="3"
android:shadowRadius="10"
android:text="What's Cool"
android:textColor="#003931"
android:textSize="12sp" />
</LinearLayout>
<android.support.design.widget.NavigationView
app:headerLayout="#layout/nav_header"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/gray_white"
app:menu="#menu/nav_drawer"
android:layout_gravity="start"
app:itemTextColor="#color/darkBlue"
app:itemIconTint="#color/darkBlue"
>
<include layout="#layout/nav_header"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
And you don't need to make any changes into your header layout and nav_drawer.
Just wrap the navigation view into a linear layout
<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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/nav_header_main"/>
<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:background="#00000000"
android:fitsSystemWindows="true"
app:menu="#menu/activity_main_drawer"/>
</LinearLayout>
Remove orientation from RelativeLayout. It doesn't support it
Set android:gravity="bottom" for parent RelativeLayout of header view.
My mistake, It will still scroll. You need to have custom recycler view for your navigation menu. So it scrolls in it's own container
<com.google.android.material.navigation.NavigationView
android:id="#+id/NavigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/header_rectangle"
app:itemTextColor="#color/white"
app:headerLayout="#layout/hidder_layout"
app:itemIconTint="#color/purple_700"
android:layout_gravity="start"
app:menu="#menu/navigation_menu" >
<include
layout="#layout/hidder_layout"/>
</com.google.android.material.navigation.NavigationView>

Comes navigation drawer over actionbar

I am using navigation drawer of supported library.I am using latest material design layout.please someone answer.
Blockquote
MainLayout.xml
<android.support.design.widget.NavigationView
android:id="#+id/shitstuff"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#color/primaryColorDark"
app:itemTextColor="#color/black"
app:menu="#menu/drawermenu" />
Take a LinearLayout and put your toolbar first and below toolbar put your drawer.
<LinearLayout
android:orientation="vertical"
.
.
>
<Toolbar .../>
<android.support.v4.widget.DrawerLayout.....>
<FrameLayout ..../> <!-- For holding fragments -->
<navigationview../>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
This is my implementation of navigation drawer. Use toolbar instead of old actionbar.
<?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"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:background="#color/gray93"
android:layout_height="match_parent"
android:elevation="7dp">
<!-- Main activity home page -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Toolbar layout -->
<include layout="#layout/toolbar" />
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_drawer_header"
app:menu="#menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>

Categories

Resources