Placing ActiobBar at top right - android

AFAIK ActionBar should be by default be displayed at top, but in my case it's coming at bottom.
I've followed the standard tutorial and kept all basics in check.
Here's my code and supporting screenshot:
MainActivity.java
package com.android.actionbardemo;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getActionBar();
actionBar.show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
Toast.makeText(this, "Home Option Selected", Toast.LENGTH_SHORT)
.show();
return true;
case R.id.java:
Toast.makeText(this, "Java Option Selected", Toast.LENGTH_SHORT)
.show();
return true;
case R.id.android:
Toast.makeText(this, "Android Option Selected", Toast.LENGTH_SHORT)
.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
main.xml (menu)
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_settings"
android:showAsAction="never"
android:title="#string/action_settings"/>
<item
android:id="#+id/home"
android:icon="#drawable/home"
android:showAsAction="ifRoom"
android:title="Home"/>
<item
android:id="#+id/java"
android:icon="#drawable/java"
android:showAsAction="ifRoom"
android:title="Java"/>
<item
android:id="#+id/android"
android:icon="#drawable/android"
android:showAsAction="ifRoom"
android:title="Android"/>
</menu>
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.actionbardemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:uiOptions="splitActionBarWhenNarrow" >
<activity
android:name="com.android.actionbardemo.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>
Am I doing anything wrong?
Any help appreciated.

You're using the uiOptions splitActionBarWhenNarrow in your application tag.
From the docs:
Add a bar at the bottom of the screen to display action items in the
ActionBar, when constrained for horizontal space (such as when in
portrait mode on a handset). Instead of a small number of action items
appearing in the action bar at the top of the screen, the action bar
is split into the top navigation section and the bottom bar for action
items. This ensures a reasonable amount of space is made available not
only for the action items, but also for navigation and title elements
at the top. Menu items are not split across the two bars; they always
appear together.

Related

Display App Icon in action bar under api 11

I'm writing simple tutorial app and for some reason my App icon is not showing up (I want to use it as navigate up button instead of the arrow).
As stated in the topic, I want to do it on Api level 11, however all the sollutions I've found rely on setIcon method.
getActionBar().setIcon(R.drawable.ic_launcher); //only on API >= 14
The fragment preview in Android studio 1.0.2 does show the icon, however the emulator does not, so I'd expect the resource is ok. Also, the search and delete icons are working like a charm. I've tried setting this both as Icon and a logo to no avail.
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yamba"
android:versionCode="1"
android:versionName="1.0"
>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light"
android:logo="#drawable/ic_launcher"
>
<activity
android:parentActivityName=".MainActivity"
android:name=".StatusActivity"
android:label="#string/app_name" >
</activity>
<!--- The labe is what's displayed at the taskbar!-->
<activity
android:parentActivityName=".MainActivity"
android:name=".SettingsActivity"
android:label="#string/title_activity_settings" >
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_settings.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.yamba.SettingsActivity">
<TextView android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
menu_settings.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.example.yamba.SettingsActivity">
<item android:id="#+id/action_settings" android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
SettingsActivity.java
package com.example.yamba;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class SettingsActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null){
SettingsFragment fragment = new SettingsFragment();
getFragmentManager().beginTransaction().add(android.R.id.content, fragment, fragment.getClass().getSimpleName()).commit();
setContentView(R.layout.activity_settings);
// getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
// only for API>=14
// getActionBar().setDisplayShowHomeEnabled(true);
// getActionBar().setIcon(R.drawable.ic_launcher);
}
}
#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_settings, menu);
// return true;
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch(id){
case R.id.action_settings:
startActivity(new Intent(this, SettingsActivity.class));
return true;
case R.id.action_tweet:
startActivity(new Intent(this, com.example.yamba.StatusActivity.class));
return true;
default:
return false;
}
}
}
SettingsFragment.java
package com.example.yamba;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
/**
* Created by me on 19-01-2015.
*/
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
private SharedPreferences prefs;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
public void onStart(){
super.onStart();
prefs= PreferenceManager.getDefaultSharedPreferences(getActivity());
prefs.registerOnSharedPreferenceChangeListener(this);
}
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
}
}
I've stumbled upon suggestion that I may be able to define custom style based on one of the existing styles, but can't quite figure out how to approach it.
If you need any other file, let me know and thanks for your time.
since it's API 11..
did you try using the support libraries?
try switching
getActionBar().setIcon(R.drawable.ic_launcher);
with :
getSupportActionBar().setIcon(R.drawable.ic_launcher);
tell me if it works and we'll continue from there :)

Error R.id && Theme.AppCompat.Light when i make Action

When i Edited
it's still error when i edit finish .this is my code MainActivity
package com.example.actionbar;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
//ถ้ามีการเลือก actionเกิดขึ้น object ที่นำมาใช้จะเรียกชื่อobject นี้ว่า onOptionItemSelected()
public boolean onOptionItemSelect(MenuItem item){
//ใช้switch case ในการกำหนดว่าเมือ เลือก action นี้เเล้วทำอะไร
switch (item.getItemId()){
case R.id.action_search:
Toast.makeText(this,"Menu search is selected", Toast.LENGTH_SHORT).show();
break;
case R.id.action_settings:
Toast.makeText(this,"Menu setting is selected", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
return true;
}
}
Now i add string to string.xml
<string name="action_search">Search</string>
This is my code in res/menu/main
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:name="#string/action_search"
android:showAsAction="ifRoom"/>
This is my code at manifest error at (android:label="#string/Theme.AppCompat.Light") .
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.actionbar.MainActivity"
android:label="#string/Theme.AppCompat.Light" > <<<<<<<<<<<error
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
this my error in R & Theme.AppCompat.Light.
R cannot be resolved to a variable
No resource found that matches the given name (at 'label' with value '#string/Theme.AppCompat.Light')
How can i do ??
thank you
You forgot the +. Change this android:id="#id/action_search" to this android:id="#+id/action_search".
And make sure you have declared a string with the name action_search and given it a value like Search in your strings.xml file. Ex. <string name="action_search">Search<string>.
Cheers.
You are missing +. Change it to below
<item android:id="#+id/action_search"
The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).
Check the topic under id #
http://developer.android.com/guide/topics/ui/declaring-layout.html
No resource found that matches the given name (at 'title' with value '#string/action_search').
Make sure you have action_search defined in strings.xml res/values/strings.xml
Also change it to android:showAsAction="ifRoom" and remove this xmlns:yourapp="http://schemas.android.com/apk/res-auto"
Also are you using ActionBar Compact? If so check the below link and the topic under Modify Menu resources.
http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html

Actionbarsherlock - Title not displaying

I've seen a few posts about getting the title to show in actionbarsherlock along with the icon. The icon is displaying fine, but the title does not show beside it.
Currently it shows the home icon with all the tabs beside it. What I am looking for is the home icon, then title, and below all this have the tabs show. Here is my code.
ACTIVITY
public class MainActivity extends SherlockFragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mJsonHandler = JsonHandler.getInstance(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
ab.setDisplayShowTitleEnabled(true);
ab.setDisplayShowHomeEnabled(true);
ab.setDisplayUseLogoEnabled(true);
ab.setTitle("TITLE TO SHOW");
inflater.inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId()) {
case R.id.menu_item0:
break;
case R.id.menu_item1:
break;
case R.id.menu_item2:
break;
case R.id.menu_item3:
break;
case R.id.menu_item4:
break;
case R.id.menu_item5:
break;
default:
this.onBackPressed();
break;
}
return false;
}
}
activity_main.xml (for menu)
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_item0"
android:orderInCategory="1"
android:showAsAction="always"
android:title="#string/menu_item0"/>
<item
android:id="#+id/menu_item1"
android:orderInCategory="2"
android:showAsAction="always"
android:title="#string/menu_item1"/>
<item
android:id="#+id/menu_item2"
android:orderInCategory="3"
android:showAsAction="always"
android:title="#string/menu_item2"/>
<item
android:id="#+id/menu_item3"
android:orderInCategory="4"
android:showAsAction="always"
android:title="#string/menu_item3"/>
<item
android:id="#+id/menu_item4"
android:orderInCategory="5"
android:showAsAction="always"
android:title="#string/menu_item4"/>
<item
android:id="#+id/menu_item5"
android:orderInCategory="6"
android:showAsAction="always"
android:title="#string/menu_item5"/>
Manifest
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Sherlock.Theme" >
<activity
android:name=".activities.MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Sherlock Theme
<style name="Sherlock.Theme" parent="Theme.Sherlock.Light.DarkActionBar">
</style>
You're setting too many menu items to always show in the ActionBar. You should only set the most important ones to do so. You should read through the Android Design Guidelines on the appropriate way to set up the ActionBar
Android Design Guidelines - Action Bar organization
Also, you should set up the ActionBar in onCreate and leave onCreateOptionsMenu for only inflating your menu(s). This is just a general tip and goes towards better, more professional code formatting.

Android - Spinning circle appears in Action Bar

So I have an action bar I am trying to learn and when I implement it I see this white spinning circle left of my first menu item. Why is this being shown here?
Source:
package com.example.lookingfor;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.atcAbout:
break;
case R.id.atcContact:
break;
case R.id.atcRate:
break;
}
return true;
}
}
Menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/atcAbout"
android:showAsAction="ifRoom"
android:title="About"/>
<item
android:id="#+id/atcRate"
android:showAsAction="ifRoom"
android:title="Rate this app"/>
<item
android:id="#+id/atcContact"
android:showAsAction="ifRoom"
android:title="Contact Us"/>
</menu>
Main Layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lookingfor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is a screenshot (I cannot post images here yet)
http://imgur.com/RaTTP
How can I get rid of this spinning circle before I publish the app? It is an ugly and annoying distraction to the app itself.
Thanks Y'all!
Try commenting out the line requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); in your onCreate() callback.

Combining Menu and Tab

I am using this "Tab layout and Listview" from http://www.androidhive.info/2012/05/android-combining-tab-layout-and-list-view/ and "Android Menus" from http://www.androidhive.info/2011/09/how-to-create-android-menus/.
I merge them together, yet it doesn't work. The tab works, but not for the menu.
Here are my codes.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
public class optionMenuActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
// Initiating Menu XML file (menu.xml)
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu, menu);
return true;
}
/**
* Event Handling for Individual menu item selected
* Identify single menu item by it's id
* */
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
Intent myList = new Intent();
switch (item.getItemId())
{
case R.id.menu_login:
// Single menu item is selected do something
// Ex: launching new activity/screen or show alert message
// Toast.makeText(optionMenuActivity.this, "Bookmark is Selected", Toast.LENGTH_SHORT).show();
myList = new Intent(optionMenuActivity.this, LoginActivity.class);
startActivity(myList);
return true;
case R.id.menu_save:
Toast.makeText(optionMenuActivity.this, "Save is Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_search:
Toast.makeText(optionMenuActivity.this, "Search is Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_share:
Toast.makeText(optionMenuActivity.this, "Share is Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_delete:
Toast.makeText(optionMenuActivity.this, "Delete is Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_quit:
// Toast.makeText(optionMenuActivity.this, "Preferences is Selected", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
// return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
The main from "Tab layout"
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
And this is my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item android:id="#+id/menu_login"
android:icon="#drawable/icon_bookmark"
android:title="Login" />
<item android:id="#+id/menu_save"
android:icon="#drawable/icon_save"
android:title="Save" />
<item android:id="#+id/menu_search"
android:icon="#drawable/icon_search"
android:title="Search" />
<item android:id="#+id/menu_share"
android:icon="#drawable/icon_share"
android:title="Share" />
<item android:id="#+id/menu_delete"
android:icon="#drawable/icon_delete"
android:title="Delete" />
<item android:id="#+id/menu_quit"
android:icon="#drawable/icon_preferences"
android:title="Quit" />
</menu>
And lastly, my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".WorkDroid5"
android:configChanges="keyboardHidden|orientation"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Inbox Activity -->
<activity android:name=".AnnouncementActivity" />
<!-- Outbox Activity -->
<activity android:name=".HomeworkActivity" />
<!-- Profile Activity -->
<activity android:name=".TimetableActivity" />
<activity android:name=".tt_Friday" />
<activity android:name=".ttFinalDetails" />
<activity android:name=".TimetableAdapter" />
<activity android:name=".tt_Thursday" />
<activity android:name=".tt_Monday" />
<activity android:name=".tt_Tuesday" />
<activity android:name=".tt_Wednesday" />
<activity
android:name=".RegisterActivity"
android:label="Register New Account" >
</activity>
<activity
android:name=".LoginActivity"
android:label="Login to your Account" >
</activity>
<activity
android:name=".optionMenuActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.example.OPTIONMENUACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<!-- Internet Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Thanks in advance for anyone's help (':
Here:
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu, menu);
return true;
}
you pass R.layout.menu to MenuInflater.inflate(..) method, but it should be R.menu.menu. Move your menu.xml file from res/layout dir to res/menu dir.
I ran into similar problem with TabHost. By default, Android creates an options menu for the parent activity, i.e. TabHost in your case. The child tab does not receive the OnCreateOptionsMenu event. Therefore, your menu is not being created.
Put the option menu creation/handling code in the activity extending TabActivity. You can change the preference menu content by checking which tab is currently selected by checking getTabHost.getCurrentTab or getTabHost.getCurrentTabTag and inflating appropriate menu.

Categories

Resources