Android 4.3 menu item showAsAction= always ignored
Probably you are missing required namespace:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:[yourapp]="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_add_size"
android:title="@string/menu_add_item"
android:orderInCategory="10"
[yourapp]:showAsAction="always"
android:icon="@android:drawable/ic_menu_add" />
</menu>
Replace [yourapp]
with your app name or any namespace your heart desires everywhere.
Other things worth checking:
- See if your activity class extends
ActionBarActivity
Check if the issue persists.
Android reference documentation: Adding Action Buttons. Here is the relevant text:
If your app is using the Support Library for compatibility on versions as low as Android 2.1, the showAsAction attribute is not available from the android: namespace. Instead this attribute is provided by the Support Library and you must define your own XML namespace and use that namespace as the attribute prefix. (A custom XML namespace should be based on your app name, but it can be any name you want and is only accessible within the scope of the file in which you declare it.)
Android menu item showAsAction= always doesn't work
You maybe just don't have enough space, you should first remove the title from your Activity
by adding this to your onCreate
method:
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Then you can see here that the maximum number of icons you can display is directly linked to the width of your screen, on small phones you will only be able to see 2 icons in the ActionBar
.
Menu Item showAsAction= always has no effect
To resolve your issue you have to extends ActionBarActivity. But you have to change your style
<style name="YesBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- task bar styles go here -->
</style>
With this:
<style name="YesBar" parent="Theme.AppCompat">
<!-- task bar styles go here -->
</style>
And change the order of these methods
setContentView(R.layout.activity_wallet)
super.onCreate(savedInstanceState)
to
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_wallet)
Android: using app:showAsAction= always for all menu items
If you want to be sure that you will have all the 4 icons is better to create your own ActionBar like and do whatever you like.
In the original ActionBar you can use :
android:showAsAction="always"
It will force them to be there but take in consideration what is happening if it's still not enough room.
When contained within the action bar there is a finite maximum of action items based on the device's density-independent width. The action items can also not cover more than half the width of the action bar.
from here
ExtJS: Add rel attribute to menu item
Do you mean 'ref' or 'rel' attribute? Anyway you can use the following dirty solution:
Ext.create('Ext.menu.Menu', {
width: 100,
height: 100,
floating: false, // usually you want this set to True (default)
renderTo: Ext.getBody(), // usually rendered by it's containing component
items: [{
text: 'google',
href: "http://www.google.de/",
hrefTarget: '_blank',
listeners: {
render: function(menuItem) {
menuItem.getEl().query('a')[0].setAttribute('rel', 'noopener noreferrer');
}
}
}, {
text: 'text item'
}, {
text: 'plain item',
plain: true
}]
});
Why does android need showAsAction= always to be prefixed with an alias?
If you are using the native action bar, you use android:showAsAction
. Any time you see android:
as a prefix, you know that it is an attribute defined by the Android framework.
If you are using the appcompat-v7
backport of the action bar, that comes from a library (appcompat-v7
). Libraries cannot invent new android:
attributes. Instead, for library-defined attributes, you use a new namespace (e.g., app:
) tied to a http://schemas.android.com/apk/res-auto
URL.
it says that android: namespace is not able to provide access to the property if the we pretend to support older android versions such as 2.1
Correct. In this case, while android:showAsAction
was added to the framework in Android 3.0, part of the goal of appcompat-v7
is to support back to Android 2.1. While Google has a time machine, they have not been using it to "retcon" Android and add in attributes that formerly did not exist.
(though, if they did, we wouldn't know about it, as our past would have been altered to have those attributes, unless we somehow have an existence outside the normal space-time continuum, which frequently seems to involve wearing a cape)
So, appcompat-v7
can use attributes like android:icon
, which existed from Android 1.0, but cannot support an android:showAsAction
prior to Android 3.0. Hence, they have their own attribute.
Related Topics
Finish All Activities at a Time
How to Start Service Using Alarm Manager in Android
Android How to Work with Asynctasks Progressdialog
Spinner: Get State or Get Notified When Opens
Published App on Play Store Can't Communicate with Google Maps API and Facebook API
Too Many Field References: 70613; Max Is 65536
Navigationview Onnavigationitemselectedlistener Not Being Called
Listview Click to Show Image in Imageview
Valid Values for Android:Fontfamily and What They Map To
Refreshing Oauth Token Using Retrofit Without Modifying All Calls
Android Paint: .Measuretext() VS .Gettextbounds()
How to Achieve Ripple Animation Using Support Library
How to Serialize an Object and Save It to a File in Android
Android Canvas: Drawing Too Large Bitmap
Android Inject_Events Permission
Googleservice Failed to Initialize