my NavigationView:
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="#layout/header"
app:menu="#menu/drawer"
app:itemTextColor="#android:color/black"
app:itemBackground="?attr/selectableItemBackground" />
drawer.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="#+id/mainActions"
android:checkableBehavior="single">
<item
android:id="#+id/firm"
android:checked="false"
android:icon="#drawable/firm"
android:title="#string/firm" />
<item
android:id="#+id/surveys"
android:checked="false"
android:icon="#drawable/surveys"
android:title="#string/surveys" />
<item
android:id="#+id/results"
android:checked="false"
android:icon="#drawable/results"
android:title="#string/results" />
<item
android:id="#+id/notifications"
android:checked="false"
android:icon="#drawable/notifications"
android:title="#string/notifications" />
</group>
<group
android:id="#+id/subActions"
android:checkableBehavior="single">
<item
android:id="#+id/settings"
android:checked="false"
android:icon="#drawable/settings"
android:title="#string/settings" />
<item
android:id="#+id/logout"
android:checked="false"
android:icon="#drawable/logout"
android:title="#string/logout" />
</group>
I am running the app on Android 6 Galaxy Note 4 device. When I press each navigation drawer item only the color of the icon is changed to light blue. i would like to change also the text color of each item and have ripple effect shown.
Set a color selector for the
app:itemTextColor="#color/selector_nav_items"
Where the selector itself is
res/color/selector_nav_items:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/your_light_blue_color" android:state_pressed="true"/>
<item android:color="#android:color/black"/>
</selector>
Related
So I want a navigation bar at the bottom of the screen with 4 items but for some reason only the first one is showing and the others appear only when i click them.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/white"
app:itemTextColor="#color/black"
app:menu="#menu/navigation_bar_bottom_menu" />
My menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/nav_home"
android:title="#string/navigation_bar_home_text" />
<item
android:id="#+id/nav_inbox"
android:title="#string/navigation_bar_inbox_text" />
<item
android:id="#+id/nav_notes"
android:title="#string/navigation_bar_notes_text" />
<item
android:id="#+id/nav_profile"
android:title="#string/navigation_bar_profile_text" />
</menu>
The bar is displayed like this just with the first item showing:
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/gray_background"
app:itemIconTint="#color/nav_item_state_list"
app:itemTextColor="#color/nav_item_state_list"
app:labelVisibilityMode="labeled"
android:theme="#style/Widget.BottomNavigationView"
app:menu="#menu/bottom_navigation_items"/>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/colorPrimaryLite"
android:state_pressed="true"/>
<item android:color="#color/colorPrimaryLite"
android:state_checked="true"/>
<item android:color="#color/grayDark"
android:state_checked="false"/>
<item android:color="#color/white"/>
</selector>
Here is the example
Create a color file
navigation_item_text_color.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#color/black" />
<item android:color="#android:color/darker_gray" />
</selector>
then put to color folder (if you don't have color folder -> just create it manually)
Then
<com.google.android.material.bottomnavigation.BottomNavigationView
...
app:itemTextColor="#color/navigation_item_text_color" />
More
If you bottom menu item have icon, you can change icon color like
app:itemIconTint="#color/navigation_item_text_color"
I want to set a black background with a white textview to the topmost item of the hamburger menu.It tried dynamically but setting Menu Item class does not have any propert setBackgroundDrawable etc.This is my menu and I want to set the background to navigation_item_1.pls help me
<?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/grp1" android:checkableBehavior="single" >
<item
android:id="#+id/navigation_item_1"
android:checked="true"
android:icon="#drawable/ic_home"
android:title="get i5 Pro" />
</group>
<group android:checkableBehavior="single">
<item
android:id="#+id/home"
android:icon="#drawable/ic_home"
android:title="Home"/>
<item
android:id="#+id/activate_pro"
android:icon="#drawable/ic_pro"
android:title="Active PRO"/>
<item
android:id="#+id/my_music"
android:icon="#drawable/ic_music_list"
android:title="My Music"/>
<item
android:id="#+id/nav_browse"
android:icon="#drawable/ic_brows_black"
android:title="Browse and Discover" />
<item
android:id="#+id/radio_stations"
android:icon="#drawable/ic_radio_station"
android:title="Radio Stations"/>
<item
android:id="#+id/new_releases"
android:icon="#drawable/ic_new_release"
android:title="New Releases"/>
<item
android:id="#+id/my_profile"
android:icon="#drawable/ic_profile"
android:title="My Profile" />
<item
android:id="#+id/music_lang"
android:icon="#drawable/ic_checked"
android:title="Music Languages" />
<item
android:id="#+id/settings"
android:icon="#drawable/ic_settings"
android:title="Settings"/>
<item
android:id="#+id/nav_login"
android:icon="#drawable/ic_logout"
android:title="Log in " />
<item
android:id="#+id/nav_log_out"
android:icon="#drawable/ic_logout"
android:title="Log out " />
</group>
</menu>
In xml file having navigation view add following code inside navigation view as :
<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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:layout_marginTop="330dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_home"/>
<TextView
android:id="#+id/mSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:textColor="#ffffff"
android:text="get i5 Pro" />
</LinearLayout>
</android.support.design.widget.NavigationView>
Where you have to give margin top of linear layout according to your header height.. e.g. If your header height is 320 dp then you need to increase is by 10 dp or more according to your requirement.
I am trying to create Bottom navigation view in android without a title, but I'm unable to hide the title. Also, I need to active and inactive icon colour for Bottom navigation view.
Expected design
Current design
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_alignParentBottom="true"
android:background="#color/bottom_nav_colour"
app:itemTextColor="#color/black"
app:itemIconTint="#color/black"
design:menu="#menu/bottom_navigation" />
bottom_navigation.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_home"
android:title="#string/menu_home"
android:icon="#drawable/home" />
<item
android:id="#+id/menu_search"
android:title="#string/menu_search"
android:icon="#drawable/search"/>
<item
android:id="#+id/menu_add"
android:title="#string/menu_add"
android:icon="#drawable/add"/>
<item
android:id="#+id/menu_wishlist"
android:title="#string/menu_wishlist"
android:icon="#drawable/wishlist"/>
<item
android:id="#+id/menu_account"
android:title="#string/menu_account"
android:icon="#drawable/account" />
</menu>
In the latest support library for BottomNavigationView you can use labelVisibility
You can create selector for icons.
selector_home_icon.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="drawable/home" android:state_selected="true"/>
<item android:drawable="drawable/home_disabled"/>
</selector>
Set this selector as icon drawable
bottom_navigation.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_home"
android:title="#string/menu_home"
android:icon="#drawable/selector_home_icon" />
.......
</menu>
This question already has answers here:
How to open sub menu after click on menu-item in Navigation drawer?
(3 answers)
Closed 7 years ago.
I am new in android and in my project I want to add the navigation drawer. I am selecting Navigation Drawer activity and create project in eclipse please help me how to develop navigation drawer below
Here is the image of navigation drawer for item and sub item menu
Use 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"
app:headerLayout="#layout/nav_header_main_navigation"
app:itemBackground="#drawable/nav_view_item_background"
app:itemTextColor="#color/nav_item_text_color"
app:menu="#menu/activity_main_navigation_drawer" />
activity_main_navigation_drawer code
<?xml version="1.0" encoding="utf-8"?>
<group android:checkableBehavior="single" android:id="#+id/root_group">
<item
android:id="#+id/item_home"
android:checked="true"
android:title="Home" />
<item android:title="You" android:id="#+id/you_parent_item">
<menu android:id="#+id/you_menu">
<group android:checkableBehavior="single" android:id="#+id/you_group">
<item
android:id="#+id/item_you_summary"
android:title="Summary Detail" />
<item
android:id="#+id/item_calendar"
android:title="Calendar" />
<item
android:id="#+id/item_request_timeout"
android:title="Request TimeOut" />
<item
android:id="#+id/item_cancel_requests"
android:title="Cancel Requests" />
<item
android:id="#+id/item_approval_responses"
android:title="Approval Responses" />
<item
android:id="#+id/item_transaction"
android:title="Transactions" />
<item
android:id="#+id/item_approval_request"
android:title="Approval Requests" />
<item
android:id="#+id/item_delegate"
android:title="Delegate" />
</group>
</menu >
</item>
<item android:title="Your People" android:id="#+id/your_parent_item">
<menu android:id="#+id/your_menu">
<group android:checkableBehavior="single" android:id="#+id/your_group">
<item
android:id="#+id/your_item_sumary"
android:title="View Summary" />
<item
android:id="#+id/item_record_timeout"
android:title="Record TimeOut" />
</group>
</menu>
</item>
<item android:title="Settings" android:id="#+id/setting_parent_item">
<menu android:id="#+id/setting_menu">
<group android:checkableBehavior="single" android:id="#+id/setting_group">
<item
android:id="#+id/item_log_out"
android:title="Log Out" />
</group>
</menu>
</item>
</group>
HeaderLayout if you want sent then
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/nav_header_height"
android:background="#color/cws_orange"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:theme="#style/Theme.AppTheme.AppBarOverlay">
<ImageView
android:id="#+id/imgAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#android:drawable/sym_def_app_icon" />
<TextView
android:id="#+id/txtUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text="Android Studio"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/txtUserEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android.studio#android.com" />
I am making navigation drawer with navigaiton view (content is taking from menu)
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/drawer_view"/>
I want to change the default layout of the menu from drawer_view.xml.
Is android provide any means(actionLayout not working) for changing the default layout of menus
Create drawer.xml inside menu folder and add this.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/home"
android:checked="false"
android:icon="#drawable/home"
android:title="Home" />
<item
android:id="#+id/info"
android:checked="false"
android:icon="#drawable/info"
android:title="Info" />
<item
android:id="#+id/other"
android:checked="false"
android:icon="#drawable/other"
android:title="Other" />
<item
android:id="#+id/other1"
android:checked="false"
android:icon="#drawable/other1"
android:title="Other 1" />
<item android:title="Sub Menus">
<menu>
<item
android:id="#+id/sub_one"
android:icon="#drawable/sub"
android:title="Sub item 1" />
<item
android:id="#+id/sub_two"
android:icon="#drawable/sub"
android:title="Sub item 2" />
<item
android:id="#+id/sub3"
android:icon="#drawable/sub"
android:title="Sub item 3" />
<item
android:id="#+id/sub4"
android:icon="#drawable/sub"
android:title="Sub item 4" />
</menu>
</item>
</group>
</menu>
And replace
app:menu="#menu/drawer_view"
inside NavigationView with this
app:menu="#menu/drawer"
So you can edit images and text for each menu option.