Icon not displaying in ActionBar - android

I have used actionbar in my app. I have 3 icons on actionbar, but when the app runs it only shows 2 icons i.e. First and the last one, not mid one. I want to show all of them everytime.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<!-- Share, should appear as action button -->
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_action_share"
android:showAsAction="ifRoom"
android:title="Generate QR"
yourapp:showAsAction="ifRoom"/>
**<!-- NOT SHOWING THIS ONE -->
<item
android:id="#+id/action_save"
android:icon="#drawable/ic_action_save"
android:showAsAction="ifRoom"
android:title="Generate QR"
yourapp:showAsAction="ifRoom"/>**
<item
android:id="#+id/action_nav_menu"
android:icon="#drawable/ic_action_overflow"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="Menu"
yourapp:showAsAction="always"/>

As you want all 3 items to be displayed every time, include yourapp:showAsAction="always" in each item.

Related

Showing Icons for Inner Menu Items, but not Showing Icon for Main Menu Items

As you can see, I am using Icon with each and every Menu Item, Main and Inner both the Menu Items contains Icon.
Issue: Showing Icons for Inner Menu Items, but not for Main Menu Items
1. Showing Icons for `Inner 1` and `Inner 2`
2. Not showing for `Main 1` and `Main 2`
menu.xml
<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.akoscz.youtube.YouTubeActivity" >
<item
android:id="#+id/action_settings1"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Main 1"
app:showAsAction="never">
<menu>
<item
android:id="#+id/action_settings2"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Inner 1"
app:showAsAction="never"/>
<item
android:id="#+id/action_settings3"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Inner 2"
app:showAsAction="never"/>
</menu>
</item>
<item
android:id="#+id/action_settings4"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Main 2"
app:showAsAction="never"/>
</menu>
Actually I was tried thing same before unfortunately not find any solution so I just go trough this possible solution.
Made a parent menu a showAlways it will keep your icon visible in action bar area and it will open your submenu.
<item
android:id="#+id/action_settings1"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:title="Main 1"
app:showAsAction="showAlways">

How to show always 5 items in Action mode menu like WhatsApp in Android toolbar

<?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.

Align one item to left of ActionBar

I want to align one item to the left of ActionBar and others to the right like this :
I have 5 items in my menu xml.
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="fr.mgs.consulting.allbrary_android.MainActivity" >
<item
android:id="#+id/action_spinner"
android:showAsAction="always"
android:actionLayout="#layout/spinner_actionbar"
android:title="#string/action_spinner"
android:orderInCategory="1"/>
<item
android:id="#+id/action_search"
android:showAsAction="always"
android:title="#string/action_spinner"
android:icon="#drawable/ic_action_search"
android:orderInCategory="2"/>
<item
android:id="#+id/action_tablet"
android:showAsAction="never"
android:title="#string/action_spinner"
android:icon="#drawable/ic_action_tablet"
android:orderInCategory="3"/>
<item
android:id="#+id/action_notifications"
android:showAsAction="always"
android:title="#string/action_spinner"
android:icon="#drawable/ic_action_notifications"
android:orderInCategory="4"/>
<item
android:id="#+id/action_user"
android:showAsAction="always"
android:title="#string/action_spinner"
android:icon="#drawable/ic_action_user"
android:orderInCategory="5"/>
How shall we do it?
Sorry for my very bad English.
You can create your own custom view for ActionBar where this left element will be like simple image view, and others menu items will be as usual menu items.
Example here: http://javatechig.com/android/actionbar-with-custom-view-example-in-android

How to move action bar icons to overflow icons automatically?

I know two ways to show action bar icons. My minimum sdk is 14 and target sdk 19. I am debugging with android 4.2.
First one
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/mPre"
android:icon="#drawable/ic_action_previous_item"
android:showAsAction="always"
android:title="Previous"/>
<item
android:id="#+id/mNext"
android:icon="#drawable/ic_action_next_item"
android:showAsAction="ifRoom"
android:title="Next"/>
<item
android:id="#+id/mShare"
android:icon="#drawable/ic_action_share"
android:showAsAction="ifRoom"
android:title="Share"/>
<item
android:id="#+id/mFb"
android:icon="#drawable/fb"
android:showAsAction="ifRoom"
android:title="Facebook"/>
<item
android:id="#+id/mhelp"
android:icon="#drawable/ic_action_help"
android:showAsAction="ifRoom"
android:title="Help"/>
</menu>
This will show icon dynamically (2 or 3 as consider space of action bar). But problem is, this is not showing extra menu in overflow icon. When I touch my phone menu bar, extra menu will appears, but I want extra menu in overflow icon.
For solution my second code.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/mPre"
android:icon="#drawable/ic_action_previous_item"
android:showAsAction="always"
android:title="Previous"/>
<item
android:id="#+id/mNext"
android:icon="#drawable/ic_action_next_item"
android:showAsAction="always"
android:title="Next"/>
<item
android:id="#+id/mMore"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always"
android:title="More">
<menu>
<item
android:id="#+id/mShare"
android:icon="#drawable/ic_action_share"
android:showAsAction="ifRoom"
android:title="Share"/>
<item
android:id="#+id/mFb"
android:icon="#drawable/fb"
android:showAsAction="never"
android:title="Facebook"/>
<item
android:id="#+id/mhelp"
android:icon="#drawable/ic_action_help"
android:showAsAction="never"
android:title="Help"/>
</menu>
</item>
</menu>
The problem of this code this is not really dynamic. I am showing here two icon always and put others icon in overflow icon, this overflow icon is not real overflow icon.
Now what I want?
I want if I have five menu as much as menu will show in action bar and rest of the icons are stored in overflow icon automatically.
I hope you guys get my problem. Please help me. Thanks in advance.
i think you need to use this
android:showAsAction="ifRoom|withText"
the parameter showAsAction decides where the icon is to be shown
refer to this link and the documentation
If I understand correctly, you want the the action bar icons to always show on the overflow? If that's the case, you can try the following:
<item
android:id="#+id/action_settings"
android:title="Test"
app:showAsAction="never" />

Android Action bar Sherlock show actions items in dropdown always

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.

Categories

Resources