I set an icon for BottomNavigationView but it not show .
My code:
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="?android:attr/windowBackground"
app:menu="#menu/navigation" />
Menu :
<item
android:id="#+id/navigation_home"
android:icon="#drawable/ic_tab_bhxh"
android:title="#string/main_tab_social_bhxh"
app:showAsAction="ifRoom" />
<item
android:id="#+id/navigation_dashboard"
android:icon="#drawable/ic_tab_bhxh"
android:title="#string/main_tab_social_bhyt"
app:showAsAction="ifRoom" />
<item
android:id="#+id/navigation_notifications"
android:icon="#drawable/ic_tab_bhxh"
android:title="#string/main_tab_social_news"
app:showAsAction="ifRoom" />
and my program :
If you have any suggest , please tell my know .
After tried some image with different background , I resolved my issue with icon background color is white .
Related
I am working on an android app where I have to take icons of bottom navigation bar transparent without any tint layer. How can I do that?
I have tried #android:itemIconTint="#color/tranparent" But it is not working
Here is my code :
activity_main.xml:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/bottom_round_bg"
app:elevation="10dp"
app:itemTextColor="#color/black"
app:labelVisibilityMode="unlabeled"
app:itemHorizontalTranslationEnabled="false"
app:itemIconSize="30dp"
app:menu="#menu/bottom_nav_menu" />
bottom_nav_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"[![enter image description here][1]][1]
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_home"
android:title="#string/home"/>
<item
android:id="#+id/nav_trimester"
android:icon="#drawable/ic_trimester_chart"
app:itemIconTint="#android:color/transparent"
android:title="#string/trimester_chart"/>
<item
android:id="#+id/nav_tools"
android:icon="#drawable/ic_tools"
app:itemIconTint="#android:color/transparent"
android:title="#string/tools"/>
<item
android:id="#+id/nav_dairy"
android:icon="#drawable/ic_calendar_and_diary_logo"
app:itemIconTint="#android:color/transparent"
android:title="#string/calendar_and_diary"/>
<item
android:id="#+id/nav_blogs"
android:icon="#drawable/ic_blogs"
app:itemIconTint="#android:color/transparent"
android:title="#string/blogs"/>
</menu>
okay, Google Keeps-Notes and Lists App have a navigation drawer like this,
Google Keeps-Notes and Lists App Navigation Drawer(Original)
I want to do same exact as I mention in this image. I want this
'EDIT'
I want that EDIT (the TextView) at right side of navigation drawer.
I achieved this far,My Navigation Drawer
<group>
<item android:title="LABALS"
android:actionLayout="#layout/main_nav_drawer_edit">
<menu>
<item
android:id="#+id/navigation_drawer_lable"
android:title="Label 1" />
<item
android:id="#+id/navigation_drawer_create_new_label"
android:title="Create new label" />
</menu>
</item>
what should I do to achieve this, Is it possible?
Create a custom View and apply to the app:actionLayout attribute of your <item>.
<item
android:id="#+id/grp_labeled"
android:title="LABALS"
app:actionLayout="#layout/main_nav_drawer_edit">
<menu>
<item
android:id="#+id/navigation_drawer_lable"
android:title="Label 1" />
<item
android:id="#+id/navigation_drawer_create_new_label"
android:title="Create new label" />
</menu>
</item>
layout:
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EDIT"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
like this?
I have the menu item that consists of 5 items which are Home, Property, Help, Users & Account. My question is, how should I do to make the Help menu looks like the picture below. Can someone help me?
Here is my xml code for menu
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#+id/nav_home"
android:icon="#drawable/bottom_menu_home_s"
android:title="Home" />
<item
android:id="#+id/nav_property"
android:icon="#drawable/bottom_menu_property_s"
android:title="Property" />
<item
android:id="#+id/nav_panic"
android:icon="#drawable/bottom_menu_panic"
android:title="Help" />
<item
android:id="#+id/nav_user"
android:icon="#drawable/bottom_menu_users_s"
android:title="Users" />
<item
android:id="#+id/nav_account"
android:icon="#drawable/bottom_menu_accounts_s"
android:title="Account" />
Try this, as you can not do directly
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
app:itemIconTint="#color/colorPrimary"
app:itemTextColor="#android:color/black"
app:menu="#menu/bottom_navigation"
android:clipChildren="false"
android:layout_height="56dp">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/help_button"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
app:elevation="6dp"
android:scaleType="center"/>
</com.google.android.material.bottomnavigation.BottomNavigationView>
You have to download/create customized icon first. Menu doesn't allow customization like a drawable.
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 just added the BottomNavigation into my android app, but two of my four icons in there don't have the right color.
This is how it looks like in Android Studio Preview:
And this is how it looks like on the device:
All the icons are in my drawable folder.
This is the xml for the BottomNavigation:
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#color/colorAccent"
app:itemTextColor="#color/colorAccent"
app:menu="#menu/bottom_navigation_main" />
And this is the xml for the items:
<item
android:id="#+id/action_home"
android:enabled="true"
android:icon="#drawable/ic_home_white_48dp"
android:title="#string/home"
app:showAsAction="always" />
<item
android:id="#+id/action_requests"
android:enabled="true"
android:icon="#drawable/ic_collections_white_48dp"
android:title="#string/requests"
app:showAsAction="always" />
<item
android:id="#+id/action_profile"
android:enabled="true"
android:icon="#drawable/ic_account_circle_white_48dp"
android:title="#string/profile"
app:showAsAction="always" />
<item
android:id="#+id/action_recents"
android:enabled="true"
android:icon="#drawable/ic_schedule_white_48dp"
android:title="#string/recents"
app:showAsAction="always" />
Hope you can help me.
While making a selector, always keep the default state at the end, otherwise only default state would be used. You need to reorder the items in your selector as:
And the state to be used with BottomNavigationBar is state_checked not state_selected.