2016-11-05 3 views
0

Ich möchte ein Menü mit einer Löschoption machen. Die eigentliche Löschfunktion ist noch nicht abgeschlossen, da ich die obere Leiste in meiner App momentan nicht sehen kann.Android-Menü wird nicht angezeigt

Haupt Layout (activity_main.xml):

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="billy.cs436.placebadgesapp.MainActivity"> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/newPlace" 
     android:text="@string/newPlaceButton" 
    /> 
</RelativeLayout> 

Menü-Layout (main.xml):

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:id="@+id/deleteMenu" 
     android:icon="@drawable/clear" 
     android:title="@string/deleteMenu" 
     app:showAsAction="ifRoom" 
    /> 
</menu> 

Haupttätigkeit (MainActivity.java):

package billy.cs436.placebadgesapp; 

import android.content.Intent; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.widget.Toast; 

public class MainActivity extends Activity { 

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

     newPlace = (Button) findViewById(R.id.newPlace); 
     newPlace.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       Intent intent = new Intent(getApplicationContext(), setLocation.class); 
       startActivity(intent); 
      } 
     }); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the main; this adds items to the action bar if it is present. 

     getMenuInflater().inflate(R.menu.main, menu);//Menu Resource, Menu 
     return true; 
    } 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     int id = item.getItemId(); 
     if(id == R.id.deleteMenu) { 
     // if there are no badges, toast message saying so (needs implementing) 
      Toast.makeText(this, "There are no badges to delete!", Toast.LENGTH_SHORT).show(); 
     //else clear all badges 
     } else { 
      Toast.makeText(this, "Badges cleared!", Toast.LENGTH_SHORT).show(); 
     } 
     return super.onOptionsItemSelected(item); 
     } 

    } 

Can jemand sagt mir, warum der Button "Neuer Ort" das einzige ist, was bei der Ausführung angezeigt wird?

EDIT: @ T. S hat die richtige Antwort. Vielen Dank.

+0

Welchen Stil wählen Sie in AndroidManifest? – AndroidHacker

Antwort

0

Ändern Sie Ihre Klasse zu erweitern AppCompatActivity anstelle von Activity.