2014-03-30 127 views
0

我是一名Android初學者,與ActionBar合作項目,但我被卡住了。菜單不是ActionBar卡在操作欄android

activity_main_actions.xml

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
<!-- Search/will display always --> 
<item android:id="@+id/action_search" 
     android:icon="@drawable/ic_action_search" 
     android:title="@string/action_search" 
     android:showAsAction="ifRoom"/> 

<!-- Location Found --> 
<item android:id="@+id/action_location_found" 
     android:icon="@drawable/ic_action_location_found" 
     android:title="@string/action_location_found" 
     android:showAsAction="ifRoom" /> 

<!-- Refresh --> 
<item android:id="@+id/action_refresh" 
     android:icon="@drawable/ic_action_refresh" 
     android:title="@string/action_refresh" 
     android:showAsAction="ifRoom" /> 

<!-- Help --> 
<item android:id="@+id/action_help" 
     android:icon="@drawable/ic_action_help" 
     android:title="@string/action_help" 
     android:showAsAction="never"/> 

<!-- Check updates --> 
<item android:id="@+id/action_check_updates" 
     android:icon="@drawable/ic_action_refresh" 
     android:title="@string/action_check_updates" 
     android:showAsAction="never" /> 
</menu>' 


</resources>' 

MainActivity.class

public class MainActivity extends ActionBarActivity { 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     MenuInflater inflater = getMenuInflater(); 
     inflater.inflate(R.menu.activity_main_actions, menu); 
     return super.onCreateOptionsMenu(menu); 
    } 

} 

回答

1

添加按照您的activity_main_actions.xml命名空間

   xmlns:yourapp="http://schemas.android.com/apk/res-auto" 

而且取代

  android:showAsAction 

隨着

  yourapp:showAsAction 

現在,您的最終代碼會像

<?xml version="1.0" encoding="utf-8"?> 
    <menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:yourapp="http://schemas.android.com/apk/res-auto" > 
    <!-- Search/will display always --> 
<item android:id="@+id/action_search" 
    android:icon="@drawable/ic_action_search" 
    android:title="@string/action_search" 
    yourapp:showAsAction="ifRoom"/> 

    <!-- Location Found --> 
<item android:id="@+id/action_location_found" 
    android:icon="@drawable/ic_action_location_found" 
    android:title="@string/action_location_found" 
    yourapp:showAsAction="ifRoom" /> 

    <!-- Refresh --> 
    <item android:id="@+id/action_refresh" 
    android:icon="@drawable/ic_action_refresh" 
    android:title="@string/action_refresh" 
    yourapp:showAsAction="ifRoom" /> 

    <!-- Help --> 
    <item android:id="@+id/action_help" 
    android:icon="@drawable/ic_action_help" 
    android:title="@string/action_help" 
    yourapp:showAsAction="never"/> 

    <!-- Check updates --> 
    <item android:id="@+id/action_check_updates" 
    android:icon="@drawable/ic_action_refresh" 
    android:title="@string/action_check_updates" 
    yourapp:showAsAction="never" /> 
    </menu> 
    </resources> 

,讓我知道,如果存在問題

+0

但是,只有搜索和位置圖標來了其餘三件物品不會來。 –

+0

改變總是或ifRoom在「yourapp:showAsAction =」從不「 –