I'm trying to attach custom layout for menu items on DrawerLayout, but as you see menu items don't have full width and i can't resolve this problem
My menu layout
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:id="#+id/groupOne">
<item
android:id="#+id/inbox"
app:actionLayout="#layout/create_new"/>
</group>
</menu>
and my custom layout for that as create_new
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height="25dp"
android:text="New Text"
android:gravity="left|center"
android:layout_marginLeft="20dp"
android:background="#000"
android:textColor="#fff"/>
</LinearLayout>
Yeah, the only way that worked for me was to set android:layout_width="100000dp" on the custom layout's root view.
Ugly ugly hack, however.
Add custom Spinner in Navigation menu / Navigation drawer / menu item.
1) Create Menu Item in menu directory.
<menu>
> <item
> android:id="#+id/navigation_drawer_item3"
> app:actionLayout="#layout/nav_drawer_home_spinner"
> tools:ignore="MenuTitle,icon" />
</menu>
2)Navigation drawer where you can put all types of navigation drawer
here.
- header
-menu with icon
-menu without icon
-custom menu item (Spineer)
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#color/md_white_1000"
tools:openDrawer="start">
<include
layout="#layout/app_bar_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="0dp"
android:background="#color/md_white_1000"
android:nestedScrollingEnabled="true"
android:layout_gravity="start">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical"
android:background="#color/md_white_1000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/md_white_1000">
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_with_icon"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center"
android:elevation="0dp"
android:background="#color/md_white_1000"
app:itemTextColor="#color/colorAccent"
app:itemIconTint="#color/colorAccent"
app:headerLayout="#layout/nav_header_dashboard"
android:theme="#style/NavigationViewStyle"
app:menu="#menu/activity_dashboard_drawer"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_without_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/md_white_1000"
app:itemTextColor="#color/colorAccent"
android:elevation="0dp"
android:layout_gravity="bottom"
android:theme="#style/NavigationViewStyleOnlyText"
app:menu="#menu/activity_dashboard_withouticon_drawer"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
android:layout_gravity="bottom"
app:menu="#menu/activity_dashboard_spinner"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
3) Custom row_spinner_layout for putting your custom layout for menu
item of that navigation view.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_profilPic"
android:layout_width="0dp"
android:layout_weight="0.15"
android:layout_height="wrap_content"
android:padding="3dp"
android:src="#drawable/profilepic" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.7"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#color/colorAccent"
android:text=""/>
<TextView
android:id="#+id/tv_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#color/colorAccent"
android:text=""/>
</LinearLayout>
</LinearLayout>
Related
In my main activity there is navigation drawer and fab button and inside content.xml which is the main xml to load content in my Main activity. In other word, I've navigation drawer activity provided by android studio.
Code in that content.xml is:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/b1"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#f0eb79"
android:foreground="?attr/selectableItemBackground"
android:drawableTop="#drawable/computer"
android:paddingTop="25dp"
android:text="Chemistry"
android:textAllCaps="false"
android:textColor="#2f2e2e"
android:textSize="18sp" />
<Button
android:id="#+id/b2"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#524d47"
android:foreground="?attr/selectableItemBackground"
android:drawableTop="#drawable/computer"
android:paddingTop="25dp"
android:text="Sports"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/b3"
android:layout_width="0dp"
android:foreground="?attr/selectableItemBackground"
android:layout_height="200dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#e7595d"
android:drawableLeft="#drawable/computer"
android:paddingLeft="45dp"
android:text="Inventions"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
And it is not completely scrolling as shown in the figure below. I also tested same xml code into another empty activity where there is NOT fab and nagivation drawer and there it is showing scrolling behaviour perfectly.
Similarly, this is my activitymain.xml's code:
<?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:openDrawer="start">
<include
layout="#layout/app_bar_main"
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"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
It worked for me after adding these attribute in scrollview:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.nepali_test.MainActivity"
tools:showIn="#layout/app_bar_main"
Please help me to make a navigation drawer with two menus and two different button to inflate the each Menu Items and click listener
Below is the Mock up and I want to make drawer like these
Navigation Drawer First Button View
Navigation Drawer Second Button View
Please check this, it will help to add a custom view. You can use tablayout and view pager
I have read your question very carefully and try to make this layout. Finally i make it .
try this code to achieve your layout
activity_home_navigation_activtiy
<?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_home_navigation_activtiy"
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--<include layout="#layout/nav_header_home_navigation" />-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".28"
android:background="#color/colorPrimary"
android:gravity="bottom"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingBottom="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/navigation_user_img"
android:layout_width="65dp"
android:layout_height="65dp"
android:src="#drawable/ic_launcher_foreground" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/navigation_user_name_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Picks App"
android:textColor="#504C4C"
android:textSize="17dp"
android:textStyle="italic" />
<TextView
android:id="#+id/navigation_user_email_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Last Name"
android:textColor="#000"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/navigation_nested"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".72"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<Button
android:id="#+id/usr_bt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="User"/>
<Button
android:id="#+id/admin_bt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="Admin"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/user_recyler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:paddingLeft="15dp"
android:scrollbars="none" />
<android.support.v7.widget.RecyclerView
android:id="#+id/admin_recyler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:paddingLeft="15dp"
android:scrollbars="none" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
In this layout i try to make custom drawable . you can also customize according to your need
see screen shot
Thank You
Does anyone have an idea about how to customize the options menu item?. so I need to change display text below icon of the option menu item in a toolbar.
Use Custom toolbar :-
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorWhite"
android:elevation="0dp"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/back_imageView"
android:layout_width="#dimen/card_h"
android:layout_height="#dimen/card_h"
android:layout_centerVertical="true"
android:contentDescription="#string/app_name"
android:paddingBottom="#dimen/small_margin"
android:paddingRight="#dimen/med_margin"
android:paddingTop="#dimen/small_margin"
android:src="#mipmap/back" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<ImageView
android:id="#+id/right_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/iv_dob"
android:layout_gravity="center"
android:contentDescription="#string/app_name" />
<TextView
android:id="#+id/first_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/lato_bold"
android:text="#string/app_name"
android:textAllCaps="true"
android:textColor="#color/colortext"
android:textSize="#dimen/normal_text_size" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
You can use custom action Layout and put into menu Item:
Here is XML for menu.
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Eventapp="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_create"
android:actionLayout="#layout/action_view_details_layout"
android:orderInCategory="50"
android:showAsAction = "always"/>
</menu>
The Layout is
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="#string/create"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:src="#drawable/icon"/>
</LinearLayout>
this will show the icon and the text in vertical fashion.
I need to set a textview with background image at the bottom part of the navigation drawer. I am unable to do it from xml.
Try below code:-
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/side_menu_bg_color"
android:fitsSystemWindows="false"
android:scrollbars="none"
android:theme="#style/NavigationDrawerStyle"
app:headerLayout="#layout/nav_header_mains"
app:itemTextAppearance="#style/NavigationDrawer"
app:itemTextColor="#color/White"
app:menu="#menu/activity_main_drawer"
app:selectableItemBackground="#drawable/nav_drawer_item_selector">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:clickable="true"
android:orientation="vertical">
<include layout="#layout/nav_bar_playback_controls" /> // This is bottom layout with black background and 2 textviews
</LinearLayout>
</android.support.design.widget.NavigationView>
nav_bar_playback_controls.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/Black"
android:padding="10dp">
<TextView
android:id="#+id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:paddingRight="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/White"
android:text="Demo text"
android:textSize="23px"
android:textStyle="bold"
android:typeface="sans" />
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/artist"
android:layout_marginTop="4dp"
android:layout_toLeftOf="#+id/play_pause"
android:ellipsize="end"
android:text="Hello there"
android:maxLines="2"
android:paddingRight="5dp"
android:textColor="#color/White"
android:textSize="31px"
android:textStyle="bold|normal"
android:typeface="sans" />
<ImageButton
android:id="#+id/play_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#null"
android:padding="8dp" />
</RelativeLayout>
Inside your activity_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="match_parent" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<android.support.design.widget.NavigationView
android:layout_above="#+id/llBottomLay"
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/llBottomLay"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#e6e6e6"
android:orientation="horizontal">
<!--place your things here-->
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
* LinearLayout of id llBottomLay need to replace by Relative or other option depending your need
Try something like this:
<?xml version="1.0" encoding="utf-8"?>
<merge>
<android.support.v4.widget.DrawerLayout>
...removed for brevity...
</android.support.v4.widget.DrawerLayout>
<TextView
...your required properties...
android:gravity="bottom" android:layout_gravity="bottom"/>
</merge>
I have a nav drawer implemented in my activity. The audience for my app is the elderly and I want the icons to be very large and take up the whole drawer height.
I am looking to have the 4 icons evenly spaced out and to have no text just big icons. I have tried playing around with the tag:
<dimen name="design_navigation_icon_size" tools:override="true"></dimen>
but I have not been able to get it to work. The icons simply keep overlapping each other when they get too big near the top. The images always seem to be contained in the header layout.
Create custom view and layout for drawer
<android.support.design.widget.NavigationView
android:id="#+id/nav_view_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_left" />
nav_header_left.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/right_side_header_bg_color"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:paddingTop="#dimen/fifty"
android:paddingRight="#dimen/twenty"
android:paddingLeft="#dimen/twenty"
android:orientation="vertical"
android:weightSum="4">
<TextView
android:id="#+id/add_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Gallery"
android:drawableLeft="#android:drawable/ic_menu_gallery"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1"
/>
<TextView
android:id="#+id/gall_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Gallery"
android:drawableLeft="#android:drawable/ic_menu_gallery"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1"
/>
<TextView
android:id="#+id/menu_add_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Gallery"
android:drawableLeft="#android:drawable/ic_menu_add"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1"
/>
<TextView
android:id="#+id/media_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_media_rew"
android:gravity="center"
android:text="Gallery" />
</LinearLayout>
Use this code for navigationView:
<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"
android:fitsSystemWindows="true"
tools:openDrawer="start"
android:theme="#style/AppTheme">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/white"
android:titleTextColor="#color/theme_color_dark"
style="#style/AppTheme"
android:theme="#style/AppTheme"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<fragment
android:id="#+id/menu_fragement"
android:tag="Menu"
android:layout_width="250dp"
android:layout_gravity="start"
android:name="com.app.medcallz.fragments.MenuFragement"
android:layout_height="match_parent"
/>
</android.support.v4.widget.DrawerLayout>
MenuFragment:
<LinearLayout
android:id="#+id/options_container"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_below="#+id/user_detail_container">
<ImageView
android:id="#+id/notificationsIcon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/nav_notificatios"
android:layout_weight="0.1"/>
<View
android:id="#+id/account_divider"
android:layout_width="fill_parent"
android:layout_height="#dimen/login_divider_width"
android:background="#color/white_color"
android:visibility="visible"
/>
</LinearLayout>