I use com.google.android.material.bottomnavigation.BottomNavigationView for the bottom menu design.
My code
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/home"
android:icon="#drawable/ic_home"
android:enabled="true"
android:title="#string/title_home" />
<item
android:id="#+id/search"
android:icon="#drawable/ic_search"
android:enabled="false"
android:title="#string/title_search"/>
...
</menu>
I want the button titles to show under all buttons but only show under the selected one.
Perhaps there is a separate function for this?
Related
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 created a custom Toolbar, but all of the elements in it have no methods of moving. I just want to replace Fenix icon in left side on the toolbar (maybe with help of margins).
Here's my XML menu code:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/risensteam_button"
android:title="#string/main"
android:icon="#drawable/ic_action_unnamed"
app:showAsAction="always" />
<item
android:id="#+id/news_button"
android:icon="#drawable/news_icon"
android:title="#string/main"
app:showAsAction="always" />
<item
android:id="#+id/ongoing_button"
android:icon="#drawable/ongoing_icon"
android:title="#string/ongoing"
app:showAsAction="always" />
<item
android:id="#+id/base_button"
android:icon="#drawable/base_icon"
android:title="#string/base"
app:showAsAction="always" />
<item
android:id="#+id/manga_button"
android:icon="#drawable/manga_icon"
android:title="#string/manga"
app:showAsAction="always" />
<item
android:id="#+id/novels_button"
android:icon="#drawable/novels_icon"
android:title="#string/novels"
app:showAsAction="always" />
you can also add custom toolbar not use action menu add as image in toolbar as per your requirement
I am trying to inflate an XML Menu inside my App, but i get the following error when I try to Deploy the App on an Emulator:
Unhandled Exception:
Java.Lang.RuntimeException: Unexpected end of document occurred
Also my XML is located in Resources/menu/main
Inflate Menu Code:
XML Code:
<?xml version="1.0" encoding="utf-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/mnuAppLogo"
android:title="logoHere"/>
<item android:id="#+id/mnuAppName"
android:title="App Name"/>
<menu>
<item android:id="#+id/submenuHelp"
android:title="Help" />
<item android:id="#+id/submenuExit"
android:title="Exit" />
</menu>
</menu>
Why is this?
Let me know if you need more code...
Thanks in advance.
UPDATE 1:
I want to make the logoHere and App Name appear in spots 1 and 2 with the other 2 Help and Exit inside the Menu.
To create a "submenu", the elements must be included within an item element:
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/mnuAppLogo" android:title="logoHere" />
<item android:id="#+id/mnuAppName" android:title="App Name">
<menu>
<item android:id="#+id/submenuHelp" android:title="Help" />
<item android:id="#+id/submenuExit" android:title="Exit" />
</menu>
</item>
</menu>
How do I make it so that the First 2 (logoHere and App Name) are not in the "Hamburger Menu" and just on the Action Bar? The Help and Exit however will be inside the Menu.
You can use showAsAction="never" to always place the menu item in the overflow menu and showAsAction="ifRoom" to display it as an action bar button IF there is room for it.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/mnuAppLogo" showAsAction="ifRoom" android:title="logoHere" />
<item android:id="#+id/mnuAppName" showAsAction="ifRoom" android:title="App Name" />
<item android:id="#+id/submenuHelp" showAsAction="never" android:title="Help" />
<item android:id="#+id/submenuExit" showAsAction="never" android:title="Exit" />
</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/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.
I've an action bar and three tabs each includes some list to display.
When I click search I want the rest of the action bar should be hidden except the list in a tab and search item it self should be enabled, where want to search.
How can I achieve it?
Edit:
<?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">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item
android:id="#+id/action_search"
android:title="#string/action_search"
android:orderInCategory="100"
android:icon="#drawable/ic_action_search"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"/>
<item android:id="#+id/home"
android:icon="#drawable/icon_home"
android:title="Home" />
<item android:id="#+id/totalCash"
android:icon="#drawable/icon_delivered"
android:title="Cod" />
<item android:id="#+id/statusForEach"
android:icon="#drawable/icon_cancelled"
android:title="Status" />
<item android:id="#+id/logout4"
android:icon="#drawable/icon_cancelled"
android:title="Logout" />
<!--<item android:id="#+id/menu_delete"
android:icon="#drawable/icon_delete"
android:title="Delete" />
<item android:id="#+id/menu_preferences"
android:icon="#drawable/icon_preferences"
android:title="Preferences" />-->
add below line to all menu items except search
app:showAsAction="ifRoom"
and in your search item add
app:iconifiedByDefault="true"
You have to implement MenuItemCompat interface to get those events. that will allow you to listen open and close and many more events. so check it.