关于这个话题的各种网站都有解释。但我没有。请一步步讲解android 2.1操作栏的使用方法。谢谢
发布于 2014-03-12 15:58:03
您需要使用support library.Download Support库中的AppCompat,并将AppCompat导入工作区。这是一个库项目,你必须在你的Android项目中引用它。
https://developer.android.com/tools/support-library/setup.html
使用上述链接中的资源检查添加库
您的活动需要ActionBarActivity。需要使用Theme.AppCompat
检查添加ActionBar @
http://developer.android.com/guide/topics/ui/actionbar.html
或者,您可以使用ActionBarSherlock。
http://actionbarsherlock.com/
发布于 2014-03-12 15:58:55
在res/menu中添加xml文件
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_refresh"
android:orderInCategory="100"
android:showAsAction="always"
android:icon="@drawable/ic_action_refresh"
android:title="Refresh"/>
<item
android:id="@+id/action_settings"
android:title="Settings">
</item>
然后在活动中
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.action_refresh){
}
return true;
} https://stackoverflow.com/questions/22345203
复制相似问题