这是一个带有可点击按钮的操作栏示例,我尝试将其应用于其他活动,但我未能成功他的代码非常简单,但我看不出他是如何做到的,这是我谈论的示例http://www.brucephillips。名称/博客/index.cfm/2011/12/28/Android-App-Development--Using-The-ActionBar-Widget 有人知道他是怎么做到的吗?当我尝试它时,动作栏不见了。这是他在java中的代码
package name.brucephillips.actionbarexample;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
public class ActionBarExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mainmenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Toast.makeText(this, "MenuItem " + item.getTitle() + " selected.", Toast.LENGTH_SHORT).show();
return true;
}
}
这是他的主菜单
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/open" android:showAsAction="ifRoom|withText" android:title="Open" android:icon="@drawable/ic_action_open"></item>
<item android:id="@+id/save" android:showAsAction="ifRoom|withText" android:title="Save" android:icon="@drawable/ic_action_save"></item>
<item android:id="@+id/close" android:showAsAction="ifRoom|withText" android:title="Close" android:icon="@drawable/ic_action_close"></item>
<item android:id="@+id/history" android:showAsAction="ifRoom|withText" android:title="History" android:icon="@drawable/ic_action_history"></item>
<item android:id="@+id/settings" android:showAsAction="ifRoom|withText" android:title="Settings" android:icon="@drawable/ic_action_settings"></item>
</menu>
这是他的主要活动
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/introduction"/>
</LinearLayout>