I am looking for a way to customize the Highlight color of items in navigation drawer like in picture above in "Inbox" item.
i want to change heights and edges of highlight press color ..
How can i do that ?
many thanks in advance.
inside drawer_item.xml do something like this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="checked state color" android:state_checked="true" />
<item android:color="your default color" />
</selector>
change your NavigationView
<android.support.design.widget.NavigationView
android:id="#+id/activity_main_navigationview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:itemIconTint="#color/drawer_item" // notice here
app:itemTextColor="#color/drawer_item" // and here
app:itemBackground="#android:color/transparent"// and here for setting the background
color to tranparent
app:menu="#menu/menu_drawer">
Related
I have a bottomnavigation view that sets an icon depending on the state if it's checked or not.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/icon_tree"
android:title="Tree"
android:icon="#drawable/bottomnav_icon_home">
</item>
</menu>
bottomnav_icon_home:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/icon_home_black" android:state_checked="false"/>
<item android:drawable="#drawable/icon_home_green" android:state_checked="true"/>
</selector>
How ever bottomnavigation is automatically highlighting the icon when android:state_checked is true.
How do I completely disable bottomnavigation's icon selection highlight?
I've tried setting app:itemIconTint="#drawable/bottom_navigation_selector" to #null however that doesn't work
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:menu="#menu/bottom_navigation_menu"
android:background="#color/colorWhite"
app:itemTextColor="#drawable/bottom_navigation_selector"
app:itemIconSize="28dp"
app:itemIconTint="#drawable/bottom_navigation_selector"
app:labelVisibilityMode="labeled"/>
bottom_navigation_selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:color="#color/forestGreen" />
<item android:color="#color/colorBlack" />
</selector>
If i understood you right, android by default sets a tint on your bottom navigation icons on selection and you would like it to be removed right.
I know how to do that in your java class not xml though.
You'll need to set setItemIconTintList method of your BottomNavigationView to null. So in wherever you set the layout write code as :
BottomNavigationView btmNav = findViewById(R.id.bottom_navigation);
btmNav.setItemIconTintList(null);
Let us know if this works for you.
try to add this line in the dimens.xml
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">#dimen/design_bottom_navigation_text_size</dimen>
You can create custom style.
There are two steps.
1- Create custom bottom_navigation_bar_icon_color.xml in drawable folder. This is the selector showed the icon highlighted or default. So you can highlight all icons or show them as default. Choose one of the following when creating your bottom_navigation_bar_icon_color.xml
Icons highlighted: <item android:alpha="1.0" android:color="?attr/colorOnPrimary" android:state_checked="true"/>
Icons default: <item android:alpha="0.6" android:color="?attr/colorOnPrimary"/>
bottom_navigation_bar_icon_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.6" android:color="?attr/colorOnPrimary"/>
</selector>
2- Add following custom style to themes.xml or styles.xml. bottom_navigation_bar_icon_color used in itemIconTint and itemTextColor
<style name="BottomNavigationThemeCustom">
<item name="enforceTextAppearance">true</item>
<item name="enforceMaterialTheme">true</item>
<item name="android:background">?attr/colorPrimary</item>
<item name="itemIconTint">#drawable/bottom_navigation_bar_icon_color</item>
<item name="itemRippleColor">#color/mtrl_navigation_bar_colored_ripple_color</item>
<item name="itemTextAppearanceInactive">?attr/textAppearanceCaption</item>
<item name="itemTextAppearanceActive">?attr/textAppearanceCaption</item>
<item name="itemTextColor">#drawable/bottom_navigation_bar_icon_color</item>
</style>
3- Use your new style for bottomNavigationBar
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
style="#style/BottomNavigationThemeCustom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:labelVisibilityMode="unlabeled"
app:menu="#menu/bottom_menu" />
4- If you want to hide the bottomNavigationBar on Scroll add following attribute to bottomNavigationBar
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
You consider create your own implementation of bottomNavigation?
When I implement the Google BottomNavigationView, I got a lot of issues, so I create a new one like this:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/grayBottomNavigationDelimiter"/>
<RadioGroup android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorNavigationBar"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatRadioButton
android:id="#+id/homeButton"
android:drawableTop="#drawable/ic_home_black_24dp"
android:text="#string/navigation_home_text"
style="#style/RadioButtonStyle"/>
...
So, can see this is easier than imagine, did you?
To add it through XML: For the attribute IconItemTint and ItemTextColor, simply use the same color that you've used for icons by default. In that case, the highlight color and default color will be the same. Will give you the required ripple effect on selecting but highlight wont be visible.
For my black color icon, I've used this:
app:itemIconTint="#color/black"
app:itemTextColor="#000000"
My entire bottom nav looks like this:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:itemIconTint="#color/black"
app:itemTextColor="#000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_nav_more_options_menu" />
I need to add a different background color i.e a grey color as in the below pictures(Click on the blue texts to view), to the current selected tab in bottom navigation. I am using the default navigation tab activity without the help of any libraries.
bottom navigation active tab highlighted
second active tab highlighted
Here is code for bottom navigation view:
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation_Userview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:itemBackground="#color/ActivityBackgroundColor"
app:itemIconTint="#drawable/navigation_item_selector"
app:itemTextColor="#drawable/navigation_item_selector"
app:menu="#menu/navigation1"/>
Here is my code for navigation item selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/Buttoncolor" android:state_checked="true" />
<item android:color="#color/TextColor" android:state_checked="false" />
this library can help you
NavigationTabBar
in gradle(app)
compile 'devlight.io:navigationtabbar:1.2.5'
simply add this in your xml file
<devlight.io.library.ntb.NavigationTabBar
android:id="#+id/navigationTabBar"
android:layout_width="match_parent"
android:layout_height="#dimen/_50sdp"
app:ntb_animation_duration="400"
app:ntb_titled="true"
app:ntb_scaled="true"
app:ntb_tinted="true"
app:ntb_bg_color="#color/colorPrimary"
app:ntb_active_color="#color/colorAccent"
app:ntb_inactive_color="#color/colorPrimary"
app:ntb_title_mode="all"
app:ntb_swiped="true"
app:ntb_icon_size_fraction="0.4"
app:ntb_title_size="#dimen/littleFontSize"/>
UPDATE
you can create selector name backgrand_nav_item.xml like below
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorAccent"
android:state_checked="true"/>
<item android:drawable="#color/colorPrimary"
android:state_checked="false"/>
</selector>
and your BottomNavigationView
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation_Userview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:itemBackground="#drawable/backgrand_nav_item"
app:itemIconTint="#drawable/navigation_item_selector"
app:itemTextColor="#drawable/navigation_item_selector"
app:menu="#menu/navigation1"/>
I want to put a selector for the color of a text in my navigation view for itemTextColor :
navigation_view :
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="225dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/bleu"
android:fitsSystemWindows="true"
app:itemTextColor=""
app:itemBackground="#drawable/item_background"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
My selector :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#color/bleu" />
<item android:state_focused="true" android:drawable="#color/bleu" />
<item android:state_checked="true" android:drawable="#color/bleu" />
</selector>
But I can't choose a file in res/drawable. Where put my selector? I've seen on internet in res/color/my_selector.xml but it's not working because it says me selector not allowed in an xml in res/color. And if I put my selector in res/colors.xml, I don't know how to select it from the colors.xml file.
Please tell me how to do?
You can reference the selector directly from your app:itemBackground attribute on your NavigationView
app:itemBackground="#drawable/my_selector"
This should work just fine
Given a NavigationView with a section with sub menu items like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Sub items">
<menu>
<item android:title="Sub item 1" />
<item android:title="Sub item 2" />
</menu>
</item>
</menu>
Question: How do I change the background color of the Sub items row?
In my experiments, it looks like the color used for the sub menu header row/item is the same as the background color of the NavigationView (android:backgroundTint and android:background) but I have not found a way to specify the two separately. I need the background color to be one color and the sub menu header row/item another color.
itemBackground, itemIconTint and itemTextColor are simple xml-attributes that can be set, though you have to use a custom prefix instead of the android: one.
Example
<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:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Other layout views -->
<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:itemBackground="#drawable/my_ripple"
app:itemIconTint="#2196f3"
app:itemTextColor="#009688"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
Example
Create a new *.xml file in /res/color - let's name it state_list.xml - with the following content:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is used when the Navigation Item is checked -->
<item android:color="#009688" android:state_checked="true" />
<!-- This is the default text color -->
<item android:color="#E91E63" />
</selector>
and the simply reference it like this: app:itemTextColor="#color/state_list"
The same goes for itemIconTint. itemBackground expects a resource id.
use compile 'com.android.support:appcompat-v7:23.1.1'
<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" />
uses to the following XML file for item backgroud: nav_view_item_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorPrimary" android:state_checked="true" />
<item android:drawable="#android:color/transparent" />
uses to the following XML file for Text Color: nav_item_text_color
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/white" android:state_checked="true" />
<item android:color="#android:color/black" />
I have searched all things and experimented but not luck with NavigationView.
itemIconTint, itemTextColor and itemBackground working with ripple effect. but problem is state selected not working in selector drawable
I have also created drawable-v21 and put ripple_navigation_selector.xml
My goal is when open drawer again previous selected item should be in
yellow color eg. Notifications item
NavigationView inside main_layout.xml
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/black"
app:headerLayout="#layout/header"
app:itemIconTint="#drawable/navigation_view_icon_tint_selector"
app:itemTextColor="#drawable/navigation_view_text_selector"
app:menu="#menu/drawer"
app1:itemBackground="#drawable/ripple_navigation_selector"
/>
ripple_navigation_selector.xml inside drawable-v21
<item
android:id="#android:id/mask"
android:drawable="#drawable/navigation_selector"/>
<item android:drawable="#drawable/navigation_selector"/>
navigation_selector.xml inside drawable-v21
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#color/left_light_yellow" android:state_pressed="true"></item>
<item android:drawable="#color/left_light_yellow" android:state_activated="true"></item>
<item android:drawable="#color/left_light_yellow" android:state_checked="true"></item>
<item android:drawable="#android:color/black"></item>
color string named left_light_yellow
<color name="left_light_yellow">#F6CE20</color>
I think you have to make your menu items checkable
<item
android:id="#+id/wishlist"
android:checkable="true"
android:title="Wishlist" />
Why do you have app1?
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/black"
app:headerLayout="#layout/header"
app:itemIconTint="#drawable/navigation_view_icon_tint_selector"
app:itemTextColor="#drawable/navigation_view_text_selector"
app:menu="#menu/drawer"
app1:itemBackground="#drawable/ripple_navigation_selector"
/>
I think that if you remove the "1" it should work:
...
app:itemBackground="#drawable/ripple_navigation_selector"
/>