开发者

calling activities from menu

开发者 https://www.devze.com 2023-03-01 12:42 出处:网络
please guide me how can i call different activities in the case instead of Toast and menu should be visible on every activity . Plus i want the same background like a wallpaper or some other thing for

please guide me how can i call different activities in the case instead of Toast and menu should be visible on every activity . Plus i want the same background like a wallpaper or some other thing for all of my activity . Thanks

Here is the code

package com.droidnova.android.howto.optionmenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class SimpleOptionMenu extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.settings:     Toast.makeText(this, "You pressed the icon!", Toast.LENGTH_LONG).show();
                                break;
            case R.id.services:     Toast.makeText(this, "You pressed the text!", Toast.LENGTH_LONG).show();
                                break;
            case R.id.icontext: Toast.makeText(this, "You pre开发者_StackOverflow社区ssed the icon and text!", Toast.LENGTH_LONG).show();
                                break;
        }
        return true;
    }
}


 @Override
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId()) 
 {
case R.id.settings:     
  Intent intent = new Intent(this, firstclass.class);
  startActivity(intent);
  break;
case R.id.services:     
  Intent intent = new Intent(this, secondclass.class);
  startActivity(intent);
  break;
case R.id.icontext: 
  Intent intent = new Intent(this, thirdclass.class);
  startActivity(intent);
  break;
    }
    return true;
}


    case R.id.settings:     
      Intent intent = new Intent(this, SettingsActivity.class);
      startActivity(intent);
      break;
    case R.id.services:     
      Intent intent = new Intent(this, ServicesActivity.class);
      startActivity(intent);
      break;
    case R.id.icontext: 
      Intent intent = new Intent(this, ThirdActivity.class);
      startActivity(intent);
      break;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号