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"
Related
How to change menu item text color in xml file
in drawable file the code looks like this file name: bottom_nav_menu_item_text_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color= "#color/bottom_nav_menu_item_selected_color"
android:state_checked="true"
android:state_selected="true"/>
<item
android:color= "#color/bottom_nav_menu_item_unselected_color"
/>
</selector>
Bottom Navigation Menu Bar looks like this in activity_main.xml
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bottom_nav_menu_bar"
app:menu="#menu/bottom_nav_menu_items"
app:itemTextColor="#drawable/bottom_nav_menu_item_text_color"
android:background="#color/white"
/>
Can add more info with SS or gif about current behaviour so exact solution can be provided
But as you asked question about changing color of BottomNavigationView text change then you can use as mentioned below
tab_text_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:color="#color/unselectedTab" />
<item android:state_selected="true" android:color="#color/selectedTab" />
<item android:color="#color/unselectedTab" />
</selector>
In Activity xml
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bottom_nav_menu_bar"
app:menu="#menu/bottom_nav_menu_items"
app:itemTextColor="#drawable/tab_text_selector"
android:background="#color/white"
/>
I am trying to put active/inactive drawables for bottomnavigationview menu items. Going through several post in SO and browsing in Google I could find only setting colour for active/inactive state using app:itembackgroundColor what I want to achieve is set drawable when selected.
I tried this for menuitems
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_home"
android:icon="#drawable/home_navigation_view_home_selector"
android:checked="false"
android:title="#string/title_home" />
<item
android:id="#+id/navigation_dashboard"
android:icon="#drawable/home_navigation_view_oppurtunity_selector"
android:checked="false"
android:title="#string/title_oppurtunity" />
<item
android:id="#+id/navigation_notifications"
android:icon="#drawable/home_navigation_view_leads_selector"
android:checked="false"
android:title="#string/title_leads" />
<item
android:id="#+id/navigation_settings"
android:icon="#drawable/home_navigation_view_settings_selector"
android:checked="false"
android:title="#string/title_settings" />
</menu>
where
home_navigation_view_home_selector/
home_navigation_view_oppurtunity_selector/
home_navigation_view_leads_selector/
home_navigation_view_settings_selector
are selector for each item.
home_navigation_view_home_selector.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_home_selected"
android:state_checked="true" />
<item android:drawable="#drawable/ic_home_black_24dp" />
</selector>
the bottomnavigationview code is as follows
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
android:foreground="?attr/selectableItemBackground"
app:menu="#menu/navigation" />
but doesn't seem to work.
Any help will be appreciated.
Try:
navigation.setItemIconTintList(null);
in your code.
Bottom Navigation View uses color tinting by default, so you have to disable it.
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>
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() {
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>