我想在應用程序中實現操作欄,我在活動中編寫了一些代碼並添加了xml文件。 但操作欄上的圖標未顯示。我嘗試很多,但我不能知道 什麼不對這個代碼如何在android中的操作欄上顯示圖標
Java代碼是在這裏:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.testmenu, menu);
return true;
}
/*public boolean onOptionsItemSelected1(MenuItem item)
{
switch(item.getItemId()){
case R.id.register:
finish();
}
return true;
}
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
/* int id = item.getItemId();
if (id == R.id.action_settings) {
}
*/
switch (item.getItemId()) {
case R.id.register:
finish();
break;
default:
break;
}
return true;
// return super.onOptionsItemSelected1(item);
}
和XML代碼
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/register"
android:title="@string/action_settings"
android:showAsAction="alway"
android:orderInCategory="100"
android:icon="@drawable/register"
/>
</menu>
我也試試這個,但直到上沒有出現行動的任何圖標酒吧 – 2015-02-07 21:04:44