2015-02-07 116 views
2

我想在應用程序中實現操作欄,我在活動中編寫了一些代碼並添加了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> 

回答

0

有一個在你的testmenu.xml一個錯字

android:showAsAction="alway" 

變化:

android:showAsAction="always" 
+0

我也試試這個,但直到上沒有出現行動的任何圖標酒吧 – 2015-02-07 21:04:44

0
android:showAsAction="alway" 

送花兒給人- >總是

UPDATE

試試這個

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:myapp="http://schemas.android.com/apk/res-auto"> 
    <item 
     android:id="@+id/register" 
     android:title="@string/action_settings" 
     android:showAsAction="always" 
     myapp:showAsAction="always" 
     android:visible="true" 
     android:icon="@drawable/register" /> 
</menu> 
+0

我也嘗試這個,但直到沒有在操作欄上出現任何圖標。 – 2015-02-07 19:41:19

+0

是Android清單文件中的任何一種編寫代碼 – 2015-02-07 19:43:24

+0

@MuhammadSohailiqbal我更新了我的答案,可能是您的訂單號中的問題 – 2015-02-07 21:03:11

相關問題