0

我正在尝试在我的应用程序中制作菜单。当我单击我制作的名为 aboutUs 的菜单按钮时,它应该打开一个 XML 文件来解释这个应用程序的用途。除非我运行应用程序并单击菜单按钮,否则应用程序会强制关闭。这是我的 mainactivity.java

 package com.JordanZimmittiDevelopers.BlazeCustomerService1;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;


 import com.JordanZimmittiDevelopers.BlazeCustomerService.R;

 public class MainActivity extends Activity implements OnClickListener {


 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 Button mail = (Button)findViewById(R.id.button1);
 mail.setOnClickListener(this);

}

@Override
public void onClick(View v) {
switch(v.getId())
{
       case R.id.button1:
          Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
          String[] recipients = new String[]{"jordanzimmitti@gmail.com", "",};
          emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
          emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "I Have A Question          Or Probelm:");
          emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "My question or problem is:");
          emailIntent.setType("text/plain");
          startActivity(Intent.createChooser(emailIntent, "Click Your Defult E-mail To Send Your Message:"));
          finish();
      break;

   }
}



Override
 public boolean onCreateOptionsMenu(android.view.Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;

}

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.aboutUs:
    Intent i = new     Intent("com.JordanZimmittiDevelopers.BlazeCustomerService.AboutThisApp");
    startActivity(i);
}
return false;

} }

4

1 回答 1

0

制作一个解释应用程序的活动,然后像这样覆盖 onCreateOptionsMenu()

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    menu.add("Help").setIcon(R.drawable.HelpButton).setIntent(new Intent(this,HelpActivity.class));
    return super.onCreateOptionsMenu(menu);
}
于 2013-09-03T03:14:11.827 回答