Navigation Drawer showing only black icons - android

I want to change navigation drawer icons, i am trying below code in Menu.xml file. But it showing only black icon.
<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".Welcome"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_kirtan"
android:icon="#drawable/point_red"
android:title="XYZ"/>
</group>
Expected output -
Please help me...!

Add below line in Activity class...
mNavigationView.setItemIconTintList(null);

Try to add color like this :
<item
android:id="#+id/nav_kirtan"
android:icon="#drawable/point_red"
android:title="XYZ"
android:tint="#color/redColor"
/>
or you can also do
mNavigationView.setItemIconTintList(null);
This disables all state based tinting.

Related

In Navigation Architecture is it possible to replace ActionBar menu completely?

I'm using AndroidX Navigation architecture and want to know is it possible to replace the ActionBar menu completely or not?
In the project, in the Menu directory, there is a home.xml file that contains a menu items:
<?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"
android:id="#+id/homeMainMenu">
<item
android:id="#+id/action_inbox"
android:icon="#drawable/ic_baseline_mail_outline_24"
android:title="#string/action_inbox"
app:showAsAction="ifRoom" />
<item android:icon="#drawable/ic_baseline_more_vert_24"
android:title="#string/app_name"
app:showAsAction="always">
<menu>
<item
android:id="#+id/action_exitapp"
android:icon="#drawable/ic_baseline_exit_to_app_24"
android:title="#string/action_exit"
app:showAsAction="never" />
</menu>
</item>
</menu>
I want to create another menu XML file like mymenu.xml and on the fragment replace it with the home menu. Because of some reason don't want to replace items.
Is it possible? If "Yes" how to handle item click?
If i got your question correct then i guess you want to create different menu for activity and its fragment. You can do that. Please check here
Remember you've to add hasOptionsMenu in fragment onCreate

How to achieve a ripple animation by clicking on a menu item?

I have a toolbar
There is a overflow that displays options in menu
On click of menu item, How to achieve a ripple animation
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menuEventsTodayId"
android:title="#string/menu_events_today" />
<item android:id="#+id/menuUpcomingEventsId"
android:title="#string/menu_upcoming_events" />
<item android:id="#+id/menuSignOutId"
android:title="#string/menu_sign_out" />
</menu>
I tried with:
<item android:id="#+id/menuEventsTodayId"
android:background="?attr/actionBarItemBackground"
android:title="#string/menu_events_today" />
Its not working, How to properly achieve it
Just add the background as ?attr/selectableItemBackground. It will automatically give ripple on Android 5+
You can use following for android version above lollipop:
android:foreground="?attr/selectableItemBackground"
for prelollipop devices, you can use following:
compile 'com.balysv:material-ripple:1.0.2'
You need to define a separate style for your toolbar in the 'values' folder then add the following items to it:
<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="android:colorControlHighlight">#color/ripple_material_dark</item>
Note:- As you can check this Link. ?android:selectableItemBackground is only properties which makes this animation.

Animating the selected icon on BottomNavigationView

I was looking at animating the VectorDrawables I currently use in my BottomNavigationView when a tab is selected like in this Material Product Study for the Owl app. However unlike for the Toolbar view when I get the icon using MenuItem.getIcon(), cast it to AnimatedVectorDrawable and call the animate() method, there is no animation.
I was wondering if there is anything I could do to achieve this, if this will be likely included in the stable Material Components library or if I am better off creating a custom view extending the BottomNavigationView class.
we can animate the bottomnavigationview icon using below code:
bottomNavigationId.menu.getItem(i).icon =
AnimatedVectorDrawableCompat.create(this, R.drawable.ic_settings_active_avd)
val anim = bottomNavigationId.menu.getItem(i).icon as Animatable
anim.start()
but this is not working api > 24
So, better approach is create an AnimatedStateListDrawable where the AVD is the transition used into android:state_checked="true". Then you can just set this as the drawable on the MenuItem and it will run the AVD when the item is selected.
Eg:
<?xml version="1.0" encoding="utf-8"?>
<animated-selector xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:targetApi="16">
<item android:id="#+id/state_on"
android:drawable="#drawable/ic_settings_active"
android:state_checked="true"/>
<item android:id="#+id/state_off"
android:drawable="#drawable/ic_settings_inactive"/>
<transition
android:drawable="#drawable/ic_settings_active_avd"
android:fromId="#id/state_off"
android:toId="#id/state_on" />
</animated-selector>
Use this animated state list drawable as icon in 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/item_settings_fragment"
android:icon="#drawable/anim_settings"
android:title="#string/settings"
app:showAsAction="always" />
...
</menu>
Checkout below link for complete understanding bottomnavigationview with animated drawables
https://medium.com/#naththeprince/delightful-animations-in-android-d6e9c62a23d3
It's currently not possible to use animated icons with BottomNavigationView. We have had this feature request submitted internally, but have deprioritized work on it.
If you would like to help add support we'd gladly accept a pr at https://github.com/material-components/material-components-android
Make an animated vector drawable by using Shape Shifter
Add this line in build.gradle(Module:app)
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
Make Drawable selector file - selector_search.xml
<?xml version="1.0" encoding="utf-8"?>
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:targetApi="16">
<item
android:id="#+id/state_on"
android:drawable="#drawable/avd_search"
android:state_checked="true" />
<item
android:id="#+id/state_off"
android:drawable="#drawable/icon_search" />
<transition
android:drawable="#drawable/avd_search"
android:fromId="#id/state_off"
android:toId="#id/state_on" />
</animated-selector>
avd search is animated vector drawable file
icon_search is normal drawable file
Use this drawable selector file as icon in 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/navigation_search"
android:icon="#drawable/selector_search"
android:title="#string/search"
/>
</menu>
Enjoy

Highlight background color in specific pages

I have 2 activities in my app. I navigate between them using a NavigationDrawer.
Activity A is "Mes cours" and Activity B is "Mes branches".
When I'm on Activity A, I'd like to change the background of the item "Mes cours", so the user knows that he's in that page.
But if I'm in Activity B, I'd like to change the background of "Mes branches".
Everything works fine, but I want to solve that problem of changing the background...
I'm using the same menu for those 2 pages. How can I do it so ?
Thank you guys.Tell me if you need more code.
My menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu_navigation">
<item
android:id="#+id/mes_cours"
android:title="Mes cours"/>
<item
android:id="#+id/mes_branches"
android:title="Mes branches"/>
</menu>
This is done by using
navigationView.getMenu().getItem(0).setChecked(true);
Here getItem(0) refers to 1st item, so for 2nd item change it to getItem(1)
Hope this helps you :)
You need to add
<group android:checkableBehavior="single">
to your following code after menu, like written under
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single"
>
<item
android:id="#+id/mes_cours"
android:title="Mes cours"/>
<item
android:id="#+id/mes_branches"
android:title="Mes branches"/>
</group>
</menu>

Can I show icon in overflow menu of Android Toolbar?

Please take in consideration that I'm refering to the Toolbar Widget(Android L/API 21+)
By overflow menu and icons I mean something like this one :
Something more difficult : Is there any way that the icons appear on the RIGHT side of the text?
create a menu in menu, for example: main_activity_actions.xml
and use this code for the toolbar, try it:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:All4One="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/algo"//some id
android:icon="#drawable/kami_nomi_zu_shiru_sekai3" //add the image
android:title="nose"
All4One:showAsAction="always">
<menu>
<item android:id="#+id/WIFI"//option to display on the menu
android:icon="#drawable/nisekoi1"//this is a option of the submenu
android:title="#string/WIFI"/>
<item android:id="#+id/DATOS"
android:icon="#drawable/nisekoi6" //this one also is a option
android:title="#string/DATOS"/>
<item android:id="#+id/BT"
android:icon="#drawable/sao1"
android:title="#string/BT"/>
<item android:id="#+id/NADA"
android:icon="#drawable/nisekoi6" //the same
android:title="#string/NADA"/>
</menu>
</item>
</menu>

Categories

Resources