- 先Create基本的<LinearLayout> ,
基本配置如下
<LinearLayout 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"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
回到Activity 觀察:
在onCreateOptionsMenu 事件中,寫了一個Log.i 觀察
Log.i("Jacky","onCreateOptionsMenu");
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);
Log.i("Jacky","onCreateOptionsMenu");
return true;
}
在onMenuItemSelected 事件中,寫了一個Log.i 觀察
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
// TODO Auto-generated method stub
Log.i("Jacky","onMenuItemSelected");
return super.onMenuItemSelected(featureId, item);
}
在onOptionsItemSelected事件中,寫了一個Log.i 觀察
public boolean onOptionsItemSelected(MenuItem item)
{
// TODO Auto-generated method stub
Log.i("Jacky","onOptionsItemSelected");
return super.onOptionsItemSelected(item);
}
執行程式,按下模擬器的Menu
在Log 中,Text 呈現onCreateOptionMenu ()
按下Setting 鍵後




沒有留言:
張貼留言