创建Android菜单

时间:2016-03-08 10:23:33

标签: android menu

我想在我的Android应用中创建一个菜单,但它在运行后不会出现。这是我的代码 Setting.xml的

     <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="fr.learning_adventure.android.itac.android_app_activity.EspacePersonnelActivity"> <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="connexion"
        />

</menu>

EspacePersonnelActivity:

public class EspacePersonnelActivity extends ActionBarActivity {


private WifiManager wifiManager;

private Learner learner;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_espacepersonnel);

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.settings, menu);
    return true;
}

1 个答案:

答案 0 :(得分:0)

试试这个......

<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  tools:context="fr.learning_adventure.android.itac.android_app_activity.EspacePersonnelActivity">
<item android:id="@+id/action_settings"
      android:title="@string/action_settings"
      android:orderInCategory="100"
      app:showAsAction="never"/>
</menu>

希望这能帮到你......