我有
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>
请帮忙! :)
答案 0 :(得分:4)
通过添加ActionBar
属性
android:showAsAction="always"
中显示单个菜单项
http://developer.android.com/guide/topics/resources/menu-resource.html