菜单未在Sherlock FragmentActivity中显示

时间:2013-09-04 17:23:04

标签: android menu actionbarsherlock

我有

import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;


public class ActivityHome extends SherlockFragmentActivity             {
                super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

  ...........
}

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.menu_main, menu);
        return true;
    }

但菜单未显示在标题栏中,而是显示在屏幕底部(通过单击设备上的“菜单”按钮)。就像正常的活动......我做错了什么?

菜单xml是:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/menu_add_record"
        android:icon="@drawable/ic_action_plus"
        android:title="@string/add"
        >
    </item>
</menu>

请帮忙! :)

1 个答案:

答案 0 :(得分:4)

通过添加ActionBar属性

,您可以在android:showAsAction="always"中显示单个菜单项

http://developer.android.com/guide/topics/resources/menu-resource.html