Draw line between menu items - android

I am not using a navigation drawer .
I only am using a menu.xml and i want to draw a line separating between these items.
I am sure that the line is drawn but i think its color is white so i cannot see it , how can i change its color?
Thank you
<menu 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"
tools:context="com.orangelabs.crypto.blindstorage.android.poc.HomeActivity">
<group android:checkableBehavior="none"
android:id="#+id/group1">
<item android:id="#+id/action_disconnect"
android:title="#string/action_disconnect"
app:showAsAction="never"/>
<item android:id="#+id/action_upload"
android:title="#string/action_upload"
app:showAsAction="never">
<menu>
<item android:id="#+id/action_chiffre"
android:title="#string/action_chiffre"
app:showAsAction="never"/>
<item android:id="#+id/action_non_chiffre"
android:title="#string/action_non_chiffre"
app:showAsAction="never"/>
</menu>
</item>
<item android:id="#+id/action_create_folder"
android:title="#string/action_create_folder"
app:showAsAction="never"/>
</group>
<group android:checkableBehavior="none"
android:id="#+id/group2">
<item android:id="#+id/action_logs"
android:title="#string/a_propos"
app:showAsAction="never"/>
</group>
</menu>

<View
android:height="1dp"
android:width="match_parent"
android: background="#android:color/grey"
/>
This is for navigation drawer, use this code in between the items.
For menu items, check this link:
How to add line divider for menu item Android

<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#android:color/darker_gray"
/>
Use this code inbetween the menu items.

Related

Navigation menu items with dropdown menu Android

I'm using Navigation Drawer. I've used a spinner layout in a menu item, but it looks bad. I'm trying to have a view like this, but IDK how.
So when I press PRODUCT, a dropdown submenu appears.
I've tried this code to do so but it's not working.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
<group android:checkableBehavior="single"
>
<item
android:id="#+id/nav_home"
android:checkable="true"
android:icon="#drawable/ic_outline_home_24"
android:title="#string/home" />
<item
android:id="#+id/nav_products"
android:checkable="true"
android:visible="true"
android:actionLayout="#android:layout/simple_spinner_dropdown_item"
android:icon="#drawable/ic_outline_shopping_bag_24"
app:showAsAction="collapseActionView"
android:title="#string/products" >
<menu>
<item
android:id="#+id/fire_alam"
android:title="#string/fire_alarms"
android:checkable="true"
app:showAsAction="never"
/>
<item
android:id="#+id/fire_fighting"
android:checkable="true"
app:showAsAction="never"
android:title="#string/fire_fighting"/>
</menu>
</item>
<item
android:id="#+id/nav_serv"
android:checkable="true"
android:icon="#drawable/ic_outline_room_service_24"
android:title="#string/services" />
</group>
</menu>
You can use ExpandableListView
Check:- https://www.journaldev.com/9942/android-expandablelistview-example-tutorial
Also you can use it in NavigationView
Check:-
https://www.journaldev.com/19375/android-expandablelistview-navigationview

Can't add Menu item next to another

I am trying to add Menu item(action_collapse_expand) next to another menu item. Problem is that item is added to expandable list(three dots icon), but not as separate icon. I've just started learning Android and I would like to know what am I doing wrong.
<?xml version="1.0" encoding="utf-8" ?>
<!--For all properties see: http://developer.android.com/guide/topics/resources/menu-resource.html-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_collapse_expand"
android:icon="#drawable/drag_drop"
android:title="Collapse"
android:showAsAction="always|withText" />
<item android:id="#+id/add" android:showAsAction="never" android:title="add" android:icon="#drawable/Add">
<menu>
<item android:id="#+id/map" android:showAsAction="always|withText" android:title="map" android:icon="#drawable/Map" />
<item android:id="#+id/mapK" android:showAsAction="always|withText" android:title=mapK" android:icon="#drawable/MapK" />
</menu>
</item>
<item android:id="#+id/exit" android:showAsAction="always" android:title="Exit" android:icon="#drawable/Close" />
</menu>
Try replacing android:showAsAction with app:showAsAction.
Don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto" under your menu tag.

Top margin for first item in navigation drawer menu in Android Studio

I am using Navigation Drawer menu without the header. The first item in the menu is too close to the top bar. How can I create margin for the first item? I am using this drawer menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Home"
android:id="#+id/nav_item_home"
android:icon="#drawable/ic_home_black_24dp"/>
<item android:title="Search Definitions"
android:id="#+id/nav_item_search"
android:icon="#drawable/ic_search_black_24dp"/>
<item android:title="About">
<menu>
<item android:title="About this app"
android:id="#+id/nav_item_about"
android:icon="#drawable/ic_info_black_24dp"/>
<item android:title="How to use this app"
android:id="#+id/nav_item_howtouse"
android:icon="#drawable/ic_perm_device_information_black_24dp"/>
</menu>
</item>
The outcome is this:
What I did as a workaround is to wrap the first item in a item menu with a blank title ... like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="">
<menu>
<item android:title="Home"
android:id="#+id/nav_item_home"
android:icon="#drawable/ic_home_black_24dp"/>
<item android:title="Search Definitions"
android:id="#+id/nav_item_search"
android:icon="#drawable/ic_search_black_24dp"/>
</menu>
</item>
<item android:title="About">
<menu>
<item android:title="About this app"
android:id="#+id/nav_item_about"
android:icon="#drawable/ic_info_black_24dp"/>
<item android:title="How to use this app"
android:id="#+id/nav_item_howtouse"
android:icon="#drawable/ic_perm_device_information_black_24dp"/>
</menu>
</item>
And then the outcome is exactly what I wanted:
Can someone please confirm if this workaround is the only way or is there any correct way of achieving the desired output.
Bit late, but any solution?
I've just played around in the xml:
<android.support.design.widget.NavigationView>
...
android:layout_marginTop="?attr/actionBarSize"
android:paddingTop="somePaddingValueInSp"
...
/>

How to show always 5 items in Action mode menu like WhatsApp in Android toolbar

<?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/menu_reply"
android:icon="#drawable/ic_reply_white_24dp"
android:title="Reply"
app:showAsAction="always" />
<item
android:id="#+id/menu_favourite"
android:icon="#drawable/ic_grade_white_24dp"
android:title="Favourite"
app:showAsAction="always" />
<item
android:id="#+id/menu_info"
android:icon="#drawable/ic_info_outline_white_24dp"
android:title="Info"
android:visible="false"
app:showAsAction="always" />
<item
android:id="#+id/menu_delete"
android:icon="#drawable/ic_delete_white_24dp"
android:title="Delete"
app:showAsAction="always" />
<item
android:id="#+id/menu_copy"
android:icon="#drawable/ic_content_copy_white_24dp"
android:title="Copy"
app:showAsAction="always" />
<item
android:id="#+id/menu_right_arrow"
android:icon="#drawable/ic_arrow_right_bold_white_24dp"
android:title="Forward"
app:showAsAction="always" />
<item
android:id="#+id/menu_message"
android:icon="#drawable/ic_arrow_right_bold_white_24dp"
android:title="Message xyz"
app:showAsAction="always" />
<item
android:id="#+id/menu_call"
android:icon="#drawable/ic_arrow_right_bold_white_24dp"
android:title="Call xyz"
app:showAsAction="always" />
</menu>
I'm using Action mode menu while long click on list item. It is always showing max 2 items, even it has space to show more items in Action mode menu. I'm assigning android:showAsAction = "always" for all the items. I'm expecting to design screen like WhatsApp long press showing 5 items with icons.
Use android:showAsAction="always" property along with app:showAsAction="always".
<item
android:id="#+id/menu_reply"
android:icon="#drawable/ic_reply_white_24dp"
android:title="Reply"
app:showAsAction="always"
android:showAsAction="always" />
Use import android.support.v7.view.ActionMode and
yourActionMode = startSupportActionMode(mActionModeCallback)
it solves this problem.

Android menu item with both icon and text together when showAsAction is never

Hi, how can I make my menu items have icons as well when showAsAction is never ?
Use android:actionLayout in menu item tag to specify custom lyout (icon with text).
Menu item will look like:
<item
android:id="#+id/edit_menu"
android:actionLayout="#layout/custom_edit_row"
android:orderInCategory="100"
android:title="#string/edit"
app:showAsAction="always"></item>
Edit
custom_edit_row.xml
will be:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
style="#android:style/Widget.ActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true">
<ImageView
android:id="#+id/imageViewEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/edit_ic" />
<TextView
android:id="#+id/tvEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit" />
<menu 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"
tools:context=".YourActivityName">
<item
android:id="#+id/action_settings"
android:icon="#android:drawable/btn_dialog"
android:title="#string/action_settings"
app:showAsAction="always">
<menu>
<item
android:id="#+id/profile"
android:icon="#drawable/common_google_signin_btn_icon_light_disabled"
android:title="PROFILE"
app:showAsAction="always" />
</menu>
</item>
Use this menu file, it worked fine for me.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_m"
android:showAsAction="never"
android:title="menu">
<menu>
<item
android:id="#+id/action_one"
android:icon="#android:drawable/ic_popup_sync"
android:showAsAction="always"
android:title="Sync"/>
<item
android:id="#+id/action_two"
android:icon="#android:drawable/ic_dialog_info"
android:title="About"/>
</menu>
</item>
</menu>
In createOptionsMenu, set the icon and text to MenuItem.
Elaborate the problem a little more.
Just change root item of Harry Mad answer
<item
android:title="Ещё"
app:showAsAction="always"
android:icon="#drawable/ic_more_vert">
...

Categories

Resources