Android BottomNavigationView disable icon title - android

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>

Related

Item showing only on click on BottomNavigationView

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"

How to display menu icons for the menu categories in the Navigation Drawer?

I can easily show icons in the menu for the subitems but what if I wanted to shows icon for the category menu items?
I tried like the code example below but it simply ignores android:icon parameter and displays just text.
First screenshot is what I get and the next one how I would like to get it looking.
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<item
android:icon="#drawable/ic_lists"
android:title="#string/lists">
<menu>
<item
android:id="#+id/nav_my_lists"
android:title="#string/my_lists" />
<item
android:id="#+id/nav_list_search"
android:title="#string/search_and_apply" />
<item
android:id="#+id/nav_list_applications"
android:title="#string/applications" />
<item
android:id="#+id/nav_list_banned"
android:title="#string/banned" />
</menu>
</item>
<item
android:icon="#drawable/ic_feedback"
android:title="#string/feedback">
<menu>
<item
android:id="#+id/nav_feedback_from_others"
android:title="#string/from_others" />
<item
android:id="#+id/nav_feedback_to_leave"
android:title="#string/i_need_to_leave" />
<item
android:id="#+id/nav_my_feedback"
android:title="#string/i_have_left" />
<item
android:id="#+id/nav_feedback_info"
android:title="#string/banned" />
</menu>
</item>
<item android:title="#string/logout" />
Question is, if there is menu icon property why it doesn't get displayed for top category menu items?
Use the Below Code
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:icon="#drawable/ic_lists"
android:title="#string/lists">
<item
android:id="#+id/nav_my_lists"
android:title="#string/my_lists"
/>
<item
android:id="#+id/nav_list_search"
android:title="#string/search_and_apply" />
<item
android:id="#+id/nav_list_applications"
android:title="#string/applications" />
<item
android:id="#+id/nav_list_banned"
android:title="#string/banned" />
<item
android:icon="#drawable/ic_feedback"
android:title="#string/feedback"/>
<item
android:id="#+id/nav_feedback_from_others"
android:title="#string/from_others" />
<item
android:id="#+id/nav_feedback_to_leave"
android:title="#string/i_need_to_leave" />
<item
android:id="#+id/nav_my_feedback"
android:title="#string/i_have_left" />
<item
android:id="#+id/nav_feedback_info"
android:title="#string/banned" />
</group>

How to change inactive color on bottom navigation?

I can't change inactive color on my bottom navigation
and this my xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/home_item"
android:icon="#drawable/ic_home"
android:color="#FFFFFF"
android:tint="#FFFFFF"
android:backgroundTint="#FFFFFF"
android:title="Home"
/>
<item
android:id="#+id/setting_item"
android:icon="#drawable/ic_setting"
android:color="#FFFFFF"
android:tint="#FFFFFF"
android:backgroundTint="#FFFFFF"
android:title="Setting"
/>
and this my java
bottomBar.getBar().setBackgroundColor(getResources().getColor(R.color.bottom_tabs));
bottomBar.setActiveTabColor("#FFFFFE");
anyone can help?
If you are using the BottomNavigationView, the solution could be easy.
You just need to create a selector as a ColorStateList, then assign the selector to the "itemIconTint" attribute of the BottomNavigationView.
For example:
Create file inside drawable
bottom_nav_icon_color_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#android:color/white" />
<item android:state_pressed="true" android:state_enabled="true" android:color="#android:color/white" />
<item android:color="#color/InactiveBottomNavIconColor" />
</selector>
BotttomNavigationview.xml
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottomNavMainMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/BottomNavBarColor"
app:itemIconTint="#drawable/bottom_nav_icon_color_selector"
app:itemTextColor="#drawable/bottom_nav_icon_color_selector"
app:menu="#menu/bottom_navigation_menu" />
Chrislis answer is a good start. However I like to solve this problem via styling and theming. I also used the new material BottomNavigationView for this example.
Create a new file under the color folder, for example: bottom_nav_item_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/item_color_active" android:state_checked="true"/>
<item android:color="#color/item_color_inactive"/>
</selector>
Add this line to your base theme located in themes.xml
<item name="bottomNavigationStyle">#style/BottomNavigationViewStyle</item>
Add this code to styles.xml
<style name="BottomNavigationViewStyle" parent="Widget.MaterialComponents.BottomNavigationView.Colored">
<item name="android:background">#color/my_background_color</item>
<item name="itemTextColor">#color/bottom_nav_item_color</item>
<item name="itemIconTint">#color/bottom_nav_item_color</item>
</style>
Now the BottomNavigationView should be styled correctly
Example layout file
<com.google.android.material.bottomnavigation.BottomNavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schema.android.com/apk/res/res-auto"
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="start"
app:menu="#menu/my_navigation_items" />
I've sligthly edited #Wirling answer to match Android Studio 4.2 Canary 16.
You just have to define your active/inactive colors under the color folder, for example bottom_nav_item.color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/item_color_active" android:state_checked="true"/>
<item android:color="#color/item_color_inactive"/>
</selector>
Then, in your BottomNavigationView just use previous created selector like this
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:itemIconTint="#color/bottom_nav_item_color"
app:itemTextColor="#color/bottom_nav_item_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_nav_menu" />
So its super simple. You have to create your selector in new .xml file and then use it for your BottomNavigationView in
app:itemIconTint="#color/bottom_nav_item_color"
app:itemTextColor="#color/bottom_nav_item_color"
Bottom Navigation select text and icon Color
first bottom navigation home layout activity
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorAccent"
android:theme="#style/ThemeOverlay.BottomNavView"
app:itemIconTint="#drawable/icon_color_selector"
app:itemTextColor="#drawable/selector"
app:labelVisibilityMode="labeled"
app:menu="#menu/home_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
then selector file create in drawable
item_color_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/bottomBarItemColor" android:state_selected="true" />
<item android:color="#color/colorDivider" android:state_selected="false" />
then create text selected color xml file in drawable
text_color_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/white" android:state_selected="true" />
<item android:color="#color/colorDivider" android:state_selected="false" />
then add style on theme xml
<style name="ThemeOverlay.BottomNavView" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorWhite</item>
<item name="colorOnSurface">#color/colorDivider</item>
<item name="android:textColorSecondary">#color/colorDivider</item>
</style>
then create home menu xml file in res directory
home_menu.xml add in menu directory
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/nav_live_date"
android:icon="#drawable/icon_selector"
android:title="Live Data"
android:enabled="true"/>
<item
android:id="#+id/nav_house_details"
android:icon="#drawable/icon_selector"
android:title="House Details"
android:enabled="true"/>
<item
android:id="#+id/nav_attendance"
android:icon="#drawable/icon_selector"
android:title="Attendance"
android:enabled="true"/>
<item
android:id="#+id/nav_emp_details"
android:icon="#drawable/icon_selector"
android:title="Emp Details"
android:enabled="true"/>
End Thank you so much
<!-- Base application theme. -->
<style name="Theme.RunnerApp"
parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?
attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
In most of the case...developer change there theme to NoActionBar
But instead of
Theme.MaterialComponents.DayNight.NoActionBar
They change it into
Theme.AppCompat.DayNight.NoActionBar
That causes all these colour issues
Navigation component use material design so keep this point in mind
Try below code. Hope its helpful!!!
mBottomBar = BottomBar.attach(this, savedInstanceState);
mBottomBar.setItems(R.menu.bottombar_menu);
mBottomBar.getBar().setBackgroundResource(R.color.navigationColor);
mBottomBar.setOnMenuTabClickListener(new OnMenuTabClickListener() {

Ripple effect not showing on navigation drawer item clicked state

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>

how can i show android:icon in android menu ( android studio)

i create application with default android studio menu, but when i change default icon with my drawable icon this circle icon is not visible.
my problem is how can i show icon in my android menu.
I used this XML:
<?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:checkableBehavior="single">
<item android:id="#+id/nav_radio" android:icon="#drawable/radio_icon"
android:title="Radio" />
<item android:id="#+id/nav_tv" android:icon="#drawable/tv_icon"
android:title="TV" />
</group>
<item android:title="Autre">
<menu>
<item android:id="#+id/nav_share" android:icon="#drawable/share_icon"
android:title="Share" />
<item android:id="#+id/nav_send" android:icon="#drawable/mail_icon"
android:title="Send" />
<item android:id="#+id/nav_like" android:icon="#drawable/heart_icon"
android:title="Rate Me" />
<item android:id="#+id/nav_recording" android:icon="#drawable/cloud_icon"
android:title="Recording" />
<item android:id="#+id/nav_close" android:icon="#drawable/power_icon"
android:title="Close" />
</menu>
</item>
</menu>
and i don't show icone
please help me
In you activity Where you have used NavigationView use this one line of code. doing this may solve your problem.
setItemIconTintList(null);
in your Activity
mNavigation = (NavigationView) findViewById(R.id.navigation);
mNavigation.setItemIconTintList(null);

Categories

Resources