Action Bar Sherlock black bar when holding on a Menu Item - android

I'm using a normal Action Bar Sherlock Action Bar but noticed that, if I opted to hold down on the item as opposed to clicking on it, a black box would appear. I have two questions:
What is its intended purpose?
How do I get rid of it?
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/refresh_button_actionbar"
android:icon="#drawable/refresh_circle"
android:showAsAction="always">
</item>
</menu>
onOptionsItemSelected:
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.refresh_button_actionbar:
this.refresh();
break;
default:
return false;
}
return true;
}

The black box is somekind of toast indicating the "description" of your button.
<item
android:id="#+id/refresh_button_actionbar"
android:icon="#drawable/refresh_circle"
android:title="Refresh"
android:showAsAction="always">
Add the android:title tag into your menu item and you will see it appear on black box, not sure how to get rid of it tough.

Related

about android toolbar, how to hide defualt setting menu in toolbar

about android Toolbar, how to hide default setting menu in toolbar
in the this activity i hava set a single icon menu,like this –
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:title=""
android:id="#+id/menu_add"
android:icon="#drawable/actionbar_add_icon"
android:showAsAction="ifRoom">
</item>
</menu>
it is menu/main_home.xml
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_home, menu);
return super.onCreateOptionsMenu(menu);
}
but it show a three dots menu. i want know why
and how to show sub menu icon image ,it is normal in the Actionbar, but hide in the Toolbar
If you want to empty the contents of the menu, go to the res/menu folder and delete the item tags from the menu_main.xml file. You will also need to delete references to the items in onOptionsItemSelected(MenuItem item). The menu dots will disappear if there are no items.
If you want to completely remove the three dots menu, then go to the onCreateOptions(...) method in your code and delete it, or simply remove the getMenuInflater().inflate(...); portion of it. You can safely remove the onOptionsItemSelected(MenuItem item) method as well because it will have no purpose.
The simplest way to make the menu disappear is to have the onCreateOptions(...) method return false.
this question is solved use app:showAsAction ="ifRoom" not android:showAsAction ="ifRoom"
<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">
<item
android:title=""
android:id="#+id/menu_button"
app:actionLayout="#layout/menu_single_button"
app:showAsAction = "always"
/></menu>

ActionBar item does not shown in Option Menu

I can't show items inside the "Menu Item" when those items are already displayed on the Action bar.
This is my onCreateOptionsMenu method:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.opt_menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
This is my opt_menu_main layout:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_act_settings"
android:title="Settings"
android:icon="#drawable/ic_action_settings"
android:showAsAction="ifRoom"/>
</menu>
I'm not using support library (my target API is 17).
If I click on the button Menu it is always empty because the item is already displayed up on the ActionBar.
I've tried to add more items but when the items goes up on the ActionBar, they are not displayed inside the options menu.
I've also tried with showAsAction="ifRoom|withText"but doesn't work.
I think this behavior is correct, but is it possible to show the same item both in Menu and Action Bar at the same time?
Thanks
Try this:
app:showAsAction="always"
but don't forget to add this line at the begin of definition:
xmlns:app="http://schemas.android.com/apk/res-auto"
The Id's for menu items must be unique. The best option is to create another menu item with another Id and set its showAsAction to "never" to force it always into the overflow menu. But their is a chance if you are also displaying other primary options it might force both into the overflow in which case you will see two menu items with the same title.
For the moment I solved like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_act_settings"
android:title="Settings"
android:icon="#drawable/ic_action_settings"
android:showAsAction="always"/>
<item
android:id="#+id/menu_settings"
android:title="Settings"
android:showAsAction="never"/>
</menu>
So in the onOptionsItemSelected method :
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_add_schedule:
case R.id.menu_act_add_schedule:
//some code
break;
}
return true;
}
I don't think this is a correct solution, because on some device where there is not enough space to add this and other items up on the ActionBar,
since they are defined as showAsAction="always", they will be overlapped on the ActionBar Title, so it can create some layout problems.
The behavior that I want is to show always the items on the option menu, and show it also in the action bar if there is enough space.
This behavior can not be obtained with showAsAction="always" .
It would be great if someone could find a better solution.
Thanks anyway.

The menu item isn't showing in the ActionBar, only in overflow menu

I have exactly the same problem as in these threads:
No actions or icons showing on the actionbar; only in overflow
Menu items won't show up in the actiobar
No one has offered a solution, so I want to bring it up again.
I have a xml-file, my_menu.xml, that look like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/delete"
android:showAsAction="ifRoom|withText"
android:icon="#drawable/ic_delete_image"
android:title="delete"/>
</menu>
My activity extends ActionBarActivity and implements these methods:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.my_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.delete:
//delete something
break;
}
return(true);
}
In my book: "A value of ifRoom means that the menu item will appear in the action bar if there is space for it" - I have tested to use ifRoom, ifRoom|withText and always, but the item always ends up in the overflow menu. I have tested the application on different devices, and it's plenty of room. Do anyone have a solution to this?
Hank
My activity extends ActionBarActivity
As is covered in the documentation, if you are using the appcompat_v7 backport of the action bar, and its associated ActionBarActivity, your menu resource needs to have showAsAction in a namespace custom to your app:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/delete"
yourapp:showAsAction="ifRoom|withText"
android:icon="#drawable/ic_delete_image"
android:title="delete"/>
</menu>
Here is a complete sample project demonstrating the use of the appcompat_v7 action bar.
Try changing it to
<item
android:id="#+id/delete"
android:showAsAction="always|withText"
android:icon="#drawable/ic_delete_image"
android:title="delete"/>
Hope this will help you.

Showing "More Menu Items" on top right drop down menu with Android ActionBarCompat

I am developing an Android app with ActionBarCompat (released by google). In tablets,it shows more menu items as a dropdown menu at top right (Image 1) but in small devices (handsets) you should hit menu button to see more items (Image 2).
Is there any way to have top right dropdown menu like tablets in handset devices? If yes, how?
Thank you.
Sure you can !
First of all, make a menu.xml in res > menu.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:technicachat="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<item
android:id="#+id/dropdown_menu"
android:showAsAction="ifRoom"
technicachat:showAsAction="ifRoom"
android:title="Options"
android:icon="#drawable/ic_menu_moreoverflow_normal_holo_light">
<menu>
<item
android:id="#+id/item1"
android:showAsAction="ifRoom"
technicachat:showAsAction="ifRoom"
android:title="Refresh"
android:icon="#drawable/ic_menu_refresh"/>
</menu>
</item>
</menu>
All items under the second menu will appear when you click on the dropdown menu button.
You don't even need to use onOptionsItemSelected to drop it.
Just proceed as usual to handle item selection.
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.item1:
/*DO STUFF*/
}
return super.onOptionsItemSelected(item);
}
In case you want pngs for your apk, they are under /your sdk path/platforms/android-xx/data/res/ and you got drawable-hdpi, mdpi etc. For example the one you need is ic_menu_moreoverflow_normal_holo_light.
Here you are ! ;)

Unable to show the 3 dotted menu in overflow - SherlockActionBar

I've searched alot around the internet. I've done what I had to, but still I'm unable to show the 3 dotted menu as I want.
Here's the relevant code:
First, my manifest min sdk is set to 9 and my targetSdk is set to 18.
The menu xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/itemMainAlbum"
android:showAsAction="ifRoom"
android:title="Set as Main Album">
</item>
<item
android:id="#+id/itemImport"
android:showAsAction="ifRoom"
android:title="Import">
</item>
<item
android:id="#+id/itemSettings"
android:showAsAction="ifRoom"
android:title="Settings">
</item>
The Activity's relevent code (extends SherlockActivity):
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.gallery_menu, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.itemImport:
startImportActivity();
return true;
case R.id.itemMainAlbum:
setMainAlbum();
return true;
case R.id.itemSettings:
// do s.th.
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Here's how my activity looks like:
The menu item in the bottom is shown only when I click on my device's menu button. The 3 dotted menu is just never shown, no matter how many menu items I add.
If you use ActionBarSherlock, you can use this little hack. It works flawlessly for me and shows the menuoverflow on every device I have tested it on.
The "3 dotted menu" will never be shown, as your device has a MENU button. The "3 dotted menu" will only appear on devices that lack a MENU button, to allow such users the ability to access the overflow. You can see what the "3 dotted menu" looks like by setting up an emulator that emulates a device with no MENU button.
You can read more about this in the "Say Goodbye to the MENU Button" Android Developers Blog post.

Categories

Resources