2016-11-05 8 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
AppCompatActivity 대신 Activity를 확장하는 클래스를 변경

.

관련 문제