0

我不明白出了什么问题,我做了一个 activity_main.xml 和 main.xml,main.xml 位于 res/menu 文件夹中,但是当我在模拟器中单击“菜单”时,它什么也没有显示..

package com.sscet.womenssafety;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class MainActivity extends Activity {
    ImageButton ib1;
    int timeonetwo;

    public void gettime(Alarmsettings a)
    {
        timeonetwo= a.getTimeone();
    }

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

        final   Handler handler=new Handler();
        final MediaPlayer mp=MediaPlayer.create(getApplicationContext(),R.raw.alarm );
        ib1=(ImageButton) findViewById(R.id.settings);
        ib1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                mp.start();
                if(timeonetwo==15){
                    handler.post(new Runnable(){
                        public void run(){
                            if(mp.getCurrentPosition()>15000)
                            mp.stop();

                        }
                });}
                if(timeonetwo==30){
                    handler.post(new Runnable(){
                        public void run(){
                            if(mp.getCurrentPosition()>30000)
                            mp.stop();

                        }
                });}
                if(timeonetwo==45){
                    handler.post(new Runnable(){
                        public void run(){
                            if(mp.getCurrentPosition()>45000)
                            mp.stop();

                        }
                });}
                if(timeonetwo==60){
                    handler.post(new Runnable(){
                        public void run(){
                            if(mp.getCurrentPosition()>60000)
                            mp.stop();

                        }
                });}

            }



        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.contact_settings:
            Intent int1 =new Intent(MainActivity.this, Alarmsettings.class);
            startActivity(int1);
            return true;

            default:
            return super.onOptionsItemSelected(item);
        }
    }

      }

这是 MAIN.XML

 <menu xmlns:android="http://schemas.android.com/apk/res/android" >
 <Item
    android:id="@+id/contact_settings"
     android:icon="@drawable/icon_contact"
    android:title="@string/contact_settings"/>
<Item
    android:id="@+id/camera_settings"
     android:icon="@drawable/icon_camera"
    android:title="@string/camera_settings"/>
<Item
    android:id="@+id/sms_settings"
     android:icon="@drawable/icon_sms"
    android:title="@string/sms_settings"/>
<Item
    android:id="@+id/alarm_settings"
     android:icon="@drawable/icon_alarm"
    android:title="@string/alarm_settings"/>
 </menu>
4

1 回答 1

2

一个很晚的帖子,但是:

在模拟器中运行时按 F2 键可切换菜单的显示(类似于按设备上的菜单按钮)。如果使用Android3.0+作为模拟操作系统,标准模拟器上的菜单按钮不起作用

于 2014-01-15T20:13:39.293 回答