Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Icon in png for bottom navigation bar android

In My Bottom navigation bar, I am using an icon in the menu XML, the icon color changed with the theme color when selected.

after the tab click the icon totally change I am totally stuck why this happens with the png image.

Bottom navigation

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/white"
        app:labelVisibilityMode="labeled"
        app:itemBackground="@color/transparent"
        app:itemTextColor="@color/black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:menu="@menu/bottom_navigation_main" />

Selector

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_compas"
        android:state_checked="false"/>
    <item android:drawable="@drawable/discover_green"
        android:state_enabled="true"/>
</selector>

Bottom_nav_menu

 <?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">
        <item
            android:id="@+id/chatMenuFragment"
            android:enabled="true"enter code here
            android:icon="@drawable/chat_selector"
            android:title="Chat"
            app:showAsAction="always" />
        <item
            android:id="@+id/contactsFragment"
            android:enabled="true"
            android:icon="@drawable/people_selector"
            android:title="People"
            app:showAsAction="always" />
        <item
            android:id="@+id/discoverFragment"
            android:enabled="true"
            android:icon="@drawable/discover_selector"
            android:title="Discovery"
            android:backgroundTint="@color/white"
            app:showAsAction="always|withText" />
        <item
            android:id="@+id/myProfileFragment"
            android:enabled="true"
            android:icon="@drawable/user_selector"
            android:title="My"
            app:showAsAction="always|withText" />
    </menu>

screenshots

Before selection:

enter image description here

After selection:

enter image description here

like image 420
Mubarak Ali Avatar asked Mar 02 '20 10:03

Mubarak Ali


People also ask

How do I add a badge to the bottom navigation view?

You can create the badge yourself in the layout xml for your bottom navigation view. Craete a frame layout and put your menu icon below the badge and create your logic to show/hide your badge view. You can use BadgeView; Or search in github.

What is the Android bottom bar called?

The Navigation bar is the menu that appears on the bottom of your screen - it's the foundation of navigating your phone. However, it isn't set in stone; you can customize the layout and button order, or even make it disappear entirely and use gestures to navigate your phone instead.

What is the bottom bar on apps called?

As the name depicts, the navigation bar is designed and placed at the extreme bottom of the app. As per standard, it usually covers the entire horizontal space, running from left to right, at the bottom of an app screen.


3 Answers

"@drawable/discover_green" check this drawble , is it what you you're getting after pressing the compass ?

you're using a state list drawable so when you press compass the icon changes to discover_green, it is same as you defined. The solution is the completely delete the state list drawble and use just the icon or changed the green dot icon to something you want to use.

like image 148
Abhinav Chauhan Avatar answered Oct 03 '22 00:10

Abhinav Chauhan


I ran into a similar issue, the problem is that by default the bottom navigation view adds a tint to the drawables and fills everything that is not transparent (like the case of your assets).

try adding this line bottomNavigationView.itemIconTintList = null

like image 23
Daniel Loaiza Avatar answered Oct 03 '22 00:10

Daniel Loaiza


The problem is that selected state apply color filter for whole not transparent part of icon. To fix your selected icon you have to make arrows on green circle transparent not white. Ask designer for change it or do it in some editor by your own.

like image 38
Eugene Troyanskii Avatar answered Oct 03 '22 00:10

Eugene Troyanskii