被困在Actionbar android

时间:2014-03-30 12:12:37

标签: android android-fragments android-actionbar

我是一名Android初学者并正在使用ActionBar开展项目,但我被困住了。菜单未来ActionBar

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 个答案:

答案 0 :(得分: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>

如果问题存在,请告诉我