2016-11-05 16 views
0

私は削除オプション付きのメニューを作りたいと思います。現時点では私のアプリで一番上のバーが見えないので、実際の削除機能はまだ作られていません。Androidメニューが表示されない

メインレイアウト(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> 

メニューレイアウト(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> 

主な活動(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); 
     } 

    } 

缶これが実行されたときに表示されるのは、[新しい場所]ボタンが唯一の理由です。

編集: @ T.Sには正しい答えがあります。ありがとうございました。

+0

AndroidManifestで選択しているスタイル – AndroidHacker

答えて

0

Activityの代わりにAppCompatActivityを拡張するようにクラスを変更してください。

関連する問題