Menu item text being clipped in unmodified basic activity - android

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

Related

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 hide menu elements in Android?

I need to trigger a function on clicking the menu icon, and I don't need to show any items inside the menu. When I tries to avoid all the items inside the menu tag, the whole icon itself gets invisible. So how could I display only the menu icon and hide its sub 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">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:icon="#drawable/ic_menu_camera"
android:title="Settings"
app:showAsAction="never" />
//removing the above item removes the whole menu title icon.
</menu>
you need to change app:showAsAction="always", as below
<?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/action_settings"
android:icon="#drawable/ic_menu_camera"
android:orderInCategory="100"
android:title="Settings"
app:showAsAction="always" />
</menu >
check this https://developer.android.com/guide/topics/resources/menu-resource.html
Either use visible = false
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:icon="#drawable/ic_menu_camera"
android:title="Settings"
android:visible=false
app:showAsAction="never" />
Or Use a Toolbar inside which add a Menu icon and set onCLickListener().

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 Studio: Put menu buttons on the left in material design

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"/>

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