Android Studio: Put menu buttons on the left in material design - android

I will start the topic by saying that I didn't see any question like mine.
So, my question is: I have a simple application to practice the material design layout style and I want to have a menu button on the left, to be able to go backwards. This is the code of the menu. I don't think that someone needs more than that:
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=".MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
<item android:id="#+id/navigate"
android:title="#string/next"
android:icon="#drawable/ic_arrow_back_white_24dp"
android:orderInCategory="200"
app:showAsAction="always"/>

Related

Menu item text being clipped in unmodified basic activity

Note: I've not added any code or modifications to this.
For some unknown reason, the stock AndroidStudio - basic activity - menu item's text is being clipped. I've tried recreating this in blank activity and had the exact same issue.
<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.gmail.islarf.derekbanas_learningandroid.MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
change app:showAsAction="never" to app:showAsAction="always|withText" and android:showAsAction="always|withText" set order to 1

Action item always appears in the overflow menu

I am using v7 Support library and using app namespace in the menu_main.xml file. Even then, the action is never displayed in the action bar but in the overflow bar. This happens even when I use app:showAsAction="always"
menu_main.xml:
<?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:context=".MainActivity">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
<item android:id="#+id/action_create_order"
android:title="#string/action_create_order"
android:orderInCategory="1"
app:showAsAction="always"
android:icon="#drawable/add_box_black_icon"
/>
</menu>
The order of the items is important - swap the create order and settings if you want to achieve your original idea.

How to change margin or padding of menu items?

Noob question. I'm using Toolbar and menu in Android app. How i can to change margin or padding between two menu items?
All answers i found is about Sharlock bar (https://stackoverflow.com/questions/15678467/how-to-add-padding-between-menu-items-in-android) or old Action bar (https://stackoverflow.com/questions/21131814/how-to-padding-between-actionbars-menu-items-icon-when-using-the-support-librare).
I think the answer near with style files, but i realy stack what parent or item name i need for my case.
My sample menu:
<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=".MainActivity">
<item android:id="#+id/menu_contents"
android:title="#string/menu_contents"
android:icon="#drawable/ic_format_list_numbered"
android:orderInCategory="2"
app:showAsAction="always" />
<item android:id="#+id/menu_search"
android:title="#string/menu_search"
android:icon="#drawable/ic_search"
android:orderInCategory="100"
app:showAsAction="always" />
<item android:id="#+id/menu_settings"
android:title="#string/menu_settings"
android:orderInCategory="100"
app:showAsAction="never" />
Thank you!
You'll want to programmatically assign an ActionProvider using setActionProvider() on the MenuItem that gets created for the items you want to change.

Android - The 3-dot dropdown menus does not appears if the device has a menu hardware button [duplicate]

This question already has answers here:
How to force action bar overflow icon to show
(2 answers)
Closed 7 years ago.
I noticed that if you are using the actionbar with a device that has a "menu" hardware button, the 3-dot dropdown menus does not shows off. So in my app i have this menu layout:
<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=".MainActivity">
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never"
android:orderInCategory="100"
/>
<item
android:id="#+id/action_credits"
android:title="#string/action_credits"
android:orderInCategory="100"
app:showAsAction="never"
/>
<item android:title="#string/action_project"
android:id="#+id/action_project"
android:orderInCategory="100"
app:showAsAction="never"
/>
</menu>
If i try my app in a device without the hardware menu button, then the 3-dots appear in the action bar, otherwise the 3-dots dropdown menu is not displayed. Why? How can I force the display of the menu to leaving aside whether the device is or is not in possession of the key hardware ?
Overflow menu (3 dot) not shown by design on devices with hardware menu button.
This is correct behaviour. Yom must not force it to show or mimic in any way.
Android phones with traditional navigation hardware keys don't display
the virtual navigation bar at the bottom of the screen. Instead, the
action overflow is available from the menu hardware key.
Try like this
<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=".MainActivity">
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:icon="#drawable/menu_icon"
app:showAsAction="always">
<menu>
<item
android:id="#+id/action_settings1"
android:title="#string/action_settings1"
app:showAsAction="never"
android:orderInCategory="100"
/>
<item
android:id="#+id/action_credits"
android:title="#string/action_credits"
android:orderInCategory="100"
app:showAsAction="never"
/>
<item android:title="#string/action_project"
android:id="#+id/action_project"
android:orderInCategory="100"
app:showAsAction="never"
/>
</menu>
</item>
</menu>

app:showAsAction="always|withText" not showing text

I have an action bar with the follwing menu:
<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="br.com.putzbati2.PrincipalActivity" >
<item android:id="#+id/action_mensagem"
android:title="Mensagem"
android:icon="#drawable/barra_superior_envelope"
android:showAsAction="always|withText" />
<item android:id="#+id/action_carro"
android:icon="#drawable/barra_superior_carro"
app:showAsAction="always"
android:title="Meus Carros"/>
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
But the withText doesnt work. It shows only the icon.
I've already try to use android:showAsAction instead of app:showAsAction and when I do this, it doesnt show the icon neither the text. Does any one know how to help me?
I've found this solution, but as I said, it doesnt work for me
app:showAsAction ifRoom is not working on appcompat action bar
You can use like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/action_mensagem"
android:title="#string/id_item_mensagem"
android:icon="#drawable/id_item_mensagem"
android:showAsAction="always|withText" />
<!-- ... another items -->
</menu>
'always|withText' will work if there is enough room, otherwise it will only place icon! You are using so much items with text, probably you don't have room. So you will see only the icon.
You can check it if you rotate your application to landscape.

Categories

Resources