Action buttons doesn't show up on Action Bar?
This is because if you use the support AppCompat ActionBar library and ActionBarActivity you should create your menus in a different than the standard way of creating xml menus in ActioBarSherlock or the default ActionBar.
So try this code :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
app:showAsAction="always" />
<item android:id="@+id/action_compose"
android:icon="@drawable/ic_action_compose"
android:title="@string/action_compose"
app:showAsAction="always"/>
</menu>
Action Button not showing in Action Bar
Change your code with the following and try again;
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="always" />
</menu>
Also make sure that you have the following part;
@Override
public boolean onCreateOptionsMenu( Menu menu )
{
getMenuInflater().inflate( R.menu.main, menu );
return true;
}
action bar buttons not showing
i found the solution to my problem.
since i have been trying to use namespace
xmlns:app="http://schemas.android.com/apk/res-auto"
then i should use
app:showAsAction="ifRoom"
instead of
android:showAsAction="ifRoom"
Android action buttons in action bar not appearing?
Since your Activity extends ActionBarActivity you would be using AppCompat from support library.
So change to
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_add"
android:icon="@drawable/ic_add"
android:title="Add"
yourapp:showAsAction="always"
/>
...
</menu>
Quoting docs
Notice that the showAsAction attribute above uses a custom namespace
defined in the tag. This is necessary when using any XML
attributes defined by the support library, because these attributes do
not exist in the Android framework on older devices. So you must use
your own namespace as a prefix for all attributes defined by the
support library.
Android action buttons are not showing in action bar, but they are in overflow menu
TO make an item appear directly in the action bar instead of the overflow use the yourapp:showAsAction ="ifRoom" just like the last line below
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="ifRoom" />
</menu>
Unable to add action buttons to my action bar in android studio
<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="1"
app:showAsAction="always"
android:icon="@drawable/ic_action_settings"
android:title="@string/action_settings"/>
<item
android:id="@+id/volume"
android:orderInCategory="2"
android:title="Volume"
android:icon="@drawable/ic_action_volume_on"
app:showAsAction="always"/>
You need to xmlns referencing res-auto and then use it as I have used in my code. Hope this helps.
Switch button not showing up in ActionBar?
your are getting error because your actionView is null. change your Switch menu code
<item
android:id="@+id/toggle_test"
android:title=""
app:showAsAction="ifRoom"
android:orderInCategory="1"
android:actionViewClass="android.widget.Switch" />
to app:actionViewClass="android.widget.Switch"
look carefully it would be app
not android
like this...
<item
android:id="@+id/toggle_test"
android:title=""
app:showAsAction="ifRoom"
android:orderInCategory="1"
app:actionViewClass="android.widget.Switch" />
and now change your java code like this
final MenuItem toggleservice = menu.findItem(R.id.toggle_test);
Switch actionView=(Switch) MenuItemCompat.getActionView(toggleservice );
actionView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Start or stop your Service
}
});
Action bar buttons only showing in the overflow
Try this app:showAsAction="always"
<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.mhmt.autotextmate.Main" >
<!-- New, should appear as action button -->
<item
android:id="@+id/action_new"
android:icon="@drawable/ic_action_new"
app:showAsAction="always"
android:title="@string/action_new"/>
<!-- Settings, should always be in the overflow -->
<item
android:id="@+id/action_settings"
android:icon="@drawable/ic_action_save"
app:showAsAction="always"
android:title="@string/action_settings"/>
Action Bar doesn't show up
Ok guys I got the solution to my very own problem.
The problem was in defining the action items in the "menu.xml".
Android documentation says you cannot use "android:showAsAction" on older devices as it does not exist in older versions. You have to use a custom namespace. Instead of saying "android:showAsAction", use "app:showAsAction" and you are good to go. Here is the attachment from official page:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
Using XML attributes from the support library:
Notice that the showAsAction attribute above uses a custom namespace defined in the tag. This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices. So you must use your own namespace as a prefix for all attributes defined by the support library.
I hope it helps someone out there.
Related Topics
Connecting Android with Ms SQL Server 2008
Findviewbyid() Returns Null for Views in a Dialog
How to Record Video from Background of Application:Android
Android Screen Size Hdpi, Ldpi, Mdpi
How to Change Screen Orientation in the Android Emulator
What Is Meant by Ems? (Android Textview)
How to Connect with Remote Debugger
How to Modify Ripple Color When Using Attr/Selectableitembackground as Background
Android Device Does Not Show Up in Adb List
How to Use the Proguard in Android Studio
Google Play App Description Formatting
What Are the Android Sdk Build-Tools, Platform-Tools and Tools? and Which Version Should Be Used
How to Test If a Fragment View Is Visible to the User
Set Font for All Textviews in Activity