I am trying to enable ActionBar in an Activity.
Here is my Manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.assistant.lab.royale"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="15"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".LabAssistant"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and here's the code :
.....
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.abmenu, menu);
return true;
}
.....
I'm following the guide over here. The ActionBar menu should show up now according to the guide but all I'm getting is the old options menu. Why?
Edit : menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menuReset"
android:alphabeticShortcut="s"
android:icon="#android:drawable/ic_menu_preferences"
android:showAsAction="withText"
android:title="#string/menu_reset"/>
<item
android:id="#+id/menuAbout"
android:alphabeticShortcut="b"
android:icon="#android:drawable/ic_menu_info_details"
android:showAsAction="withText"
android:title="#string/menu_about"/>
</menu>
Did you include showAsAction in your abmenu.xml items?
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_save"
android:icon="#drawable/ic_menu_save"
android:title="#string/menu_save"
// This line //
android:showAsAction="ifRoom|withText" />
</menu>
Related
here is my code
MainActivity
public class MainActivity extends ActionBarActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
menu_main.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=".MainActivity">
<item android:id="#+id/action_settings" android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="#+id/one" android:title="oneone"
android:orderInCategory="100" app:showAsAction="always" />
<item android:id="#+id/two" android:title="twotwo"
android:orderInCategory="100" app:showAsAction="ifRoom" />
<item android:id="#+id/three" android:title="threethree"
android:orderInCategory="100" app:showAsAction="ifRoom" />
<item android:id="#+id/four" android:title="fourfour"
android:orderInCategory="100" app:showAsAction="ifRoom" />
</menu>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sanjith.actionbartwo" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This code gives me three buttons on the actionbar and one on the overflow.
I want to get all the buttons on the bottom actionbar.I have searched the internet for this but i haven't found a solution.
Please help.
Try this http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar
<manifest ...>
<activity uiOptions="splitActionBarWhenNarrow" ... >
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
</manifest>
I have encountered this problem before unfortunately the action bar doesn't split by code you need to fill all the room available so the action bar would split by itself with your permission of course but there are no possible way to split it if it still have space
i have been looking for solutions for hours. i'm trying to split my action bar but it keeps stacking up in the top-right corner.
this is my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:balloonberry="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
balloonberry:showAsAction="always"/>
<item android:id="#+id/action_location_found"
android:icon="#drawable/ic_action_location_found"
android:title="#string/action_location_found"
balloonberry:showAsAction="always"/>
<item android:id="#+id/action_refresh"
android:icon="#drawable/ic_action_refresh"
android:title="#string/action_refresh"
balloonberry:showAsAction="always"/>
<item android:id="#+id/action_help"
android:icon="#drawable/ic_action_help"
android:title="#string/action_help"
balloonberry:showAsAction="always"/>
<item android:id="#+id/action_check_updates"
android:icon="#drawable/ic_action_refresh"
android:title="#string/action_check_updates"
balloonberry:showAsAction="always"/>
</menu>
this is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zapp.exampleproject1" >
<uses-sdk android:minSdkVersion="17"></uses-sdk>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light"
android:uiOptions="splitActionBarWhenNarrow">
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow`" />
</activity>
</application>
</manifest>
any solutions???? (i'm using a android 4.3 phone)
Neither appcompat-v7, nor the native action bar on Android 5.0+, support the split action bar. That pattern was officially discontinued as part of the Material Design overhaul. If you want that capability, you will need to put your own Toolbar at the bottom of your activity.
I have trouble seeing the icons in the ActionBar.
I also read around here in StackOverFlow, but nothing...
Here is my action.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/addAct"
android:icon="#android:drawable/ic_input_add"
android:background="#null"
app:showAsAction="always"
android:title="#string/add"
/>
<item
android:id="#+id/searchAct"
android:icon="#android:drawable/ic_menu_search"
app:showAsAction="ifRoom"
android:title="Cerca"
android:actionViewClass="android.widget.SearchView"
/>
<item
android:id="#+id/visualizza"
android:title="#string/txtVisualizza"
app:showAsAction="always"
>
</item>
Here, is AndroiManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="11"
android:maxSdkVersion="21"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WriteActivity"
android:label="#string/title_activity_write" >
</activity>
</application>
Here, MainActivity:
public class MainActivity extends Activity { ...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.action, menu);
return super.onCreateOptionsMenu(menu);
}
In the xml code, I have used the app for ShowAsAction, but this not seems be the problem.
Thanks for any help :)
You are developing app for material design ( Target SDK = 21).
It does not support Activity.
So change extends Activity to extends ActionBarActivity.
Now your menu will be visible.
And you can edit action bar using getSupportActionBar().
I am trying to implement action bar(appcompatv_7) on API version 8. Although there is no error in my code but the action bar won't show up, instead it will appear in text format by pressing menu button.
Here is the java code:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
}
Code for 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="com.example.usingsherlockkk.MainActivity" >
<item
android:id="#+id/item1"
android:icon="#android:drawable/ic_menu_add"
android:showAsAction="ifRoom"
android:title="Title1">
</item>
<item
android:id="#+id/item2"
android:icon="#android:drawable/ic_menu_delete"
android:showAsAction="ifRoom"
android:title="Title2">
</item>
<item
android:id="#+id/reset"
android:icon="#android:drawable/ic_menu_revert"
android:showAsAction="ifRoom"
android:title="Revert">
</item>
<item
android:id="#+id/item4"
android:icon="#android:drawable/ic_menu_edit"
android:showAsAction="ifRoom"
android:title="Title4">
</item>
<item
android:id="#+id/item5"
android:icon="#android:drawable/ic_menu_help"
android:showAsAction="ifRoom"
android:title="Title5">
</item>
</menu>
Manifest file code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.usingsherlockkk"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light"
android:uiOptions="splitActionBarWhenNarrow" >
<activity
android:name="com.example.usingsherlockkk.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Guys my problem is that all the menu items are displayed in overflow where only the title appears. I checked it with big/small screen devices but it remains the same.
I hope I have explained my problem well enough. Let me know if something is hazy
Try this code
#Override
protected void onCreate(Bundle arg0) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(arg0);
setContentView(R.layout.activity_main);
}
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.
The way I did it is as follows:
There was a line in AndroidManifest.xml file
android:theme="#style/AppTheme.NoActionBar"
I simply changed it to
android:theme="#style/AppTheme"
and problem was solved.
i have problem putting the menu there, in the upper right corner:
android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.mio.app"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="11"
android:targetSdkVersion="15" />
<application android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light">
<activity android:name=".Lista_preventivi"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Java:
public class Lista_preventivi extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.lista_preventivi);
}
#Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
}
menu xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_settings"
android:showAsAction="ifRoom"
android:title="#string/action_settings" />
</menu>
all works, but the menu appear only if i click the physical button on my phone, and it appear at the bottom like a normal menu.
ho can i have the icon menu in the upper right action bar, and show the menu there?
Thanks!
The theme which your are applying to the application is android:theme="#android:style/Theme.Light". it doesn't have an actionbar.
Change it to something which has an action bar like,
Theme.Sherlock.Light (Need to add ABS library)
Theme.Holo.Light
The code is just fine.
Add:
android:showAsAction="always" in your manifest file
If your sdk version is >3.0 .Else you have no other option other than implementing Sherlock Home Api.