I am having some troubles to show items in the ActionBar with AppCompat.
This code works on a normal actionbar
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/item1"
android:showAsAction="always"
android:title="Se connecter"
android:visible="true">
</item>
</menu>
But with the AppCompat library the item isn't shown..
What should I do ?
Thanks in advance :)
showAsAction is not in the android xml namespace for API < 11 try something like the following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_refresh"
android:title="#string/refresh"
yourapp:showAsAction="always"
android:icon="#drawable/ic_action_refresh" />
</menu>
Note that I've added xmlns:yourapp="http://schemas.android.com/apk/res-auto in menu attributes and changed the namespace of showAsAction from android to yourapp.
More reading here: http://developer.android.com/guide/topics/ui/actionbar.html
Related
I'm new in Android
when i set icon in drawer_menu.xml code then after when i open the
navigation drawer menu it open slowly why?
If any one have answer to this question or ever faced this type of
issues then plz reply to this question.
Here is my drawer_menu.xml code.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/home_id"
android:icon="#drawable/home"
android:title="Home"></item>
<item
android:id="#+id/id_setting"
android:icon="#drawable/setting"
android:title="Settings"></item>
</group>
<item android:title="Others">
<menu>
<item
android:id="#+id/notifications"
android:icon="#drawable/noti"
android:title="Notifications"></item>
<item
android:id="#+id/about_us"
android:icon="#drawable/aboutus"
android:title="About us"></item>
</menu>
</item>
</menu>
What is the size of icon?
use 300*300
How to add a text view in my Action bar to show data in android application.
Following is my menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<menu>
<item
android:id="#+id/action_log"
android:title="#string/action_log"
android:showAsAction="never"/>
<item
android:id="#+id/account_log"
android:title="#string/accountlog"
android:showAsAction="never"/>
<item android:id="#+id/logout"
android:title="Logout"
android:showAsAction="never"/>
</menu>
</menu>
Any changes required in strings.xml?
Change
android:showAsAction="never"
to
android:showAsAction="ifRoom"
Please check the correct case of ifRoom, I am not quite sure.
Solved by Using custom action bar Thank you all
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.
I have set three action items which am adding to the ABS through menu XML like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_share_app"
android:icon="#drawable/share_ab"
android:showAsAction="collapseActionView"
android:title="#string/menu_share_app"/>
<item
android:id="#+id/menu_search"
android:icon="#drawable/share_ab"
android:showAsAction="always"
android:title="#string/menu_search"/>
<item
android:id="#+id/menu_settings"
android:icon="#drawable/share_ab"
android:showAsAction="collapseActionView"
android:title="#string/menu_settings"/>
</menu>
I want to show the search item alwys and the other two in a dropdown, I made the showasaction as "collapseActionView" but am not getting any dropdown. Here's the sample pic of what am expecting. Thanks! :)
I just changed the code and order.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_search"
android:icon="#drawable/share_ab"
android:showAsAction="always"
android:title="#string/menu_search"/>
<item
android:id="#+id/menu_share_app"
android:icon="#drawable/share_ab"
android:showAsAction="never"
android:title="#string/menu_share_app"/>
<item
android:id="#+id/menu_settings"
android:icon="#drawable/share_ab"
android:showAsAction="never"
android:title="#string/menu_settings"/>
</menu>
If you are having physical menu button (e.g. Nexus S) in your device then the dot line will not show. Even if your AVD emulates a device with has physical menu button then same thing will happen. When you press the Menu button it’ll show up.
I am working with Android 3.0.
I am trying to build a custom menu in the action bar that has sub-menus in it.
Anybody has the XML hierarchy that should be written?
<item> elements can contain <menu> elements. I've only tested this on ICS but it looks like it should work on Honeycomb as well.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_dropdown"
android:title="More"
android:showAsAction="always">
<menu>
<item android:id="#+id/menu_one" android:title="One" />
<item android:id="#+id/menu_two" android:title="Two" />
</menu>
</item>
</menu>