/res/menu/menu.xml
Without Menu icon:
xml version="1.0" encoding="utf-8"?>menu xmlns:android="http://schemas.android.com/apk/res/android" >item android:id="@+id/opt1"
With Menu Icon:
JAVA CODE:
OPtion Menu without Xml file:
switch(item.getItemId()){case (R.id.opt1):break;case (R.id.opt2):break;case (R.id.opt3):break;case (R.id.opt4):break;case (R.id.opt5):break;return true;="Option 5" />menu>="Option 5" />menu>
Without Menu icon:
xml version="1.0" encoding="utf-8"?>menu xmlns:android="http://schemas.android.com/apk/res/android" >item android:id="@+id/opt1"
android:title
<
="Option 1" />item android:id="@+id/opt2" android:title
<
="Option 2" />item android:id="@+id/opt3" android:title
<
="Option 3" />item android:id="@+id/opt4" android:title
<
="Option 4" />item android:id="@+id/opt5" android:title
</With Menu Icon:
<?
<
<
xml version="1.0" encoding="utf-8"?>menu xmlns:android="http://schemas.android.com/apk/res/android" >item android:id="@+id/opt1" android:icon="@drawable/ic_launcher" android:title
<
="Option 1" />item android:id="@+id/opt2" android:icon="@drawable/ic_launcher" android:title
<
="Option 2" />item android:id="@+id/opt3" android:icon="@drawable/ic_launcher" android:title
<
="Option 3" />item android:id="@+id/opt4" android:icon="@drawable/ic_launcher" android:title
<
="Option 4" />item android:id="@+id/opt5" android:icon="@drawable/ic_launcher" android:title
</JAVA CODE:
package
com.demo.ui;
import
android.app.Activity; import
android.app.AlertDialog; import
android.content.DialogInterface; import
android.os.Bundle; import
android.view.Menu; import
android.view.MenuInflater; import
android.view.MenuItem; import
android.view.View.OnClickListener; import
android.view.View; import
android.view.Window; import
android.widget.Button;
public
class DemoButtonActivity extends Activity {/** Called when the activity is first created. */ @Override requestWindowFeature(Window.
setContentView(R.layout.
public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);FEATURE_NO_TITLE);main); }
@Override public boolean onCreateOptionsMenu(Menu menu) {// TODO Auto-generated method stub MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.
}
menu, menu);return true;@Override public boolean onOptionsItemSelected(MenuItem item) {// TODO Auto-generated method stub }
}
}OPtion Menu without Xml file:
package
com.demo.ui;
import
android.app.Activity;import
android.app.AlertDialog;import
android.content.DialogInterface;import
android.os.Bundle;import
android.view.Menu;import
android.view.MenuInflater;import
android.view.MenuItem;import
android.view.View.OnClickListener;import
android.view.View;import
android.view.Window;import
android.widget.Button;
public
class DemoButtonActivity extends Activity {/** Called when the activity is first created. */@OverriderequestWindowFeature(Window.
setContentView(R.layout.
}
public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);FEATURE_NO_TITLE);main); @Overridemenu.add(0, 0, 0,
menu.add(0, 1, 1,
menu.add(0, 2, 2,
menu.add(0, 3, 3,
menu.add(0, 4, 4,
}
public boolean onCreateOptionsMenu(Menu menu) {"Option 0");"Option 1");"Option 2");"Option 3");"Option 4"); return true;@Override}
}
}public boolean onOptionsItemSelected(MenuItem item) {switch(item.getItemId()){case (0):break;case (1):break;case (2):break;case (3):break;case (4):break;return true;switch(item.getItemId()){case (R.id.opt1):break;case (R.id.opt2):break;case (R.id.opt3):break;case (R.id.opt4):break;case (R.id.opt5):break;return true;="Option 5" />menu>="Option 5" />menu>
<?
<
<
No comments:
Post a Comment