Highlight background color in specific pages - android

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>

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

Navigation Drawer showing only black icons

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.

Option menu checkbox android

I have a problem with the option menu checkable item
I want the checkbox be placed right of title not under it.
He is my option.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/notif"
android:title="Notification"
android:checkable = "true"/>
</group>
</menu>
Thanks.
This will only be the case in the menu preview in Android Studio. On your device it will display as expected.
For example:
In Android Studio, mine looks like yours:
When I start the application and check, it looks like I expect:
Hope this helped!

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>

Setting state_selected in nav drawer

Hey I'm trying to add a selected state to my Nav Drawer. Everything is pretty boilerplate from the implementation here: http://developer.android.com/training/implementing-navigation/nav-drawer.html
There's some custom style in there and I'm trying to style a custom selected state for the List View (the list view that is actually the nav drawer)
I created a selector for the list items:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#color/darkerGrey" android:state_pressed="true"/>
<item android:drawable="#color/mediumGrey" android:state_selected="true"/>
</selector>
and I'm seeing the style work for the "pressed" state, but I'm not seeing the "selected" state work. In code to make it selected I'm using the ListView method setItemChecked:
mDrawerList.setItemChecked(0, true);
I've also set on my ListView the property
android:choiceMode="singleChoice"
I would greatly appreciate any advice! Thanks!
p.s. I've tried using "state_checked" as well, to no avail.
try setting this selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#color/darkerGrey" android:state_pressed="true"/>
<item android:drawable="#color/mediumGrey" android:state_selected="true"/>
</selector>
to the listView as:
android:listSelector="#drawable/your_selector"
or
to the list_row_layout that you use for inflating into the list as:
android:background="#drawable/your_selector"

Categories

Resources