so i made my own toolbar with a menu and i am infalting it:
toolbarBottom.inflateMenu (R.menu.user_interaction);
and this is the menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res/android">
<item app:title="Edit"
app:id="#+id/post"
app:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item app:id="#+id/menu_share"
app:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
app:title="Undo" />
<item app:id="#+id/test"
app:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
app:title="Redo" />
</menu>
what i get now is the 3 android option dots on the right side of my bar. If i press it my 3 menu´s appear. What i want is the 3 menu items to appear on the bar itself witht he 3 icon drawables.
Where is my mistake? Did i forgot something? :O
ok i solved it like this:
<?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:title="Edit"
android:id="#+id/post"
android:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item android:id="#+id/menu_share"
android:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
android:title="Undo" />
<item android:id="#+id/test"
android:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
android:title="Redo" />
</menu>
It should be:
<?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:title="Edit"
android:id="#+id/post"
android:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item android:id="#+id/menu_share"
android:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
android:title="Undo" />
<item android:id="#+id/test"
android:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
android:title="Redo" />
</menu>
Related
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
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.
I have a navigation drawer. In the menu, I am trying to use some icons to the items in the menu but they don't appear. it looks like this.
here is the XML for the menu
<?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:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_overview"
android:icon="#drawable/ic_bell"
android:title="#string/overview" />
<item
android:id="#+id/nav_symptoms"
android:icon="#drawable/ic_symptoms"
android:title="#string/symptoms" />
<item
android:id="#+id/nav_prevention"
android:icon="#drawable/ic_preventation"
android:title="#string/prevention" />
<item
android:id="#+id/nav_treatment"
android:icon="#drawable/ic_medicine"
android:title="#string/treatment" />
<item
android:id="#+id/nav_statistics"
android:icon="#drawable/ic_statistics"
android:title="#string/statistics" />
<item
android:id="#+id/nav_world"
android:icon="#drawable/ic_world_data"
android:title="World-wide Statistics" />
<item
android:id="#+id/nav_settings"
android:title="#string/settings" />
</group>
</menu>
all the icons that I am using are svgs and I imported them to android studio as vector assests.
what am I doing wrong here?
This question already has answers here:
How to display menu item with icon and text in AppCompatActivity
(9 answers)
Closed 4 years ago.
unable to put icons in Action bar menu list.
here is my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_more"
android:icon="#drawable/ic_ihbpro"
android:title="one"
>
<item
android:id="#+id/Home"
android:title="Home"
android:icon="#drawable/ic_dashboard"
/>
<item
android:id="#+id/ihbprom"
android:title="IHB"
android:icon="#drawable/ic_ihbpro"
/>
<item
android:id="#+id/Account"
android:title="Account"
android:icon="#drawable/ic_account"
/>
</item>
</menu>
Currently,
it's like this:
one
Home
IHB
Account
But I want it like:
[icon]one
[icon]Home
[icon]IHB
[icon]Account
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.top_menu, menu);
return super.onCreateOptionsMenu(menu);
}
Thank you in advance :)
use app:showAsAction="always" in your <item> tag
Your menu.xml will be like this.
<?xml version="1.0" encoding="utf-8"?><?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"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="#+id/action_more"
android:icon="#drawable/ic_ihbpro"
android:title="one">
<item
android:id="#+id/Home"
android:icon="#drawable/ic_dashboard"
android:title="Home"
app:showAsAction="always" />
<item
android:id="#+id/ihbprom"
android:icon="#drawable/ic_ihbpro"
android:title="IHB"
app:showAsAction="always" />
<item
android:id="#+id/Account"
android:icon="#drawable/ic_account"
android:title="Account"
app:showAsAction="always" />
</item>
</menu>
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">
...