码迷,mamicode.com
首页 > 其他好文 > 详细

menu/main.xml

时间:2017-03-12 11:43:41      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:protect   emc   switch   apk   XML   flat   over   save   ase   

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/copy"
android:orderInCategory="100"
android:title="@string/create_class"/>

<item
android:id="@+id/delete"
android:orderInCategory="100"
android:title="@string/create_exam"/>

</menu>

 

package com.example.phonemenu;

import android.os.Bundle;
import android.app.Activity;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Toast;

public class MainActivity extends Activity {

Button button;

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

button = (Button) findViewById(R.id.btn_add);
button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
PopupMenu popup = new PopupMenu(MainActivity.this,v);// 第二个参数是绑定的那个view
// 获取菜单填充器
MenuInflater inflater = popup.getMenuInflater();
// 填充菜单
inflater.inflate(R.menu.main, popup.getMenu());
// 绑定菜单项的点击事件
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.copy:
Toast.makeText(MainActivity.this, "创建课堂···", Toast.LENGTH_SHORT).show();
break;

case R.id.delete:
Toast.makeText(MainActivity.this, "创建考试···", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
return false;
}
});
popup.show();
}
});
}

}

menu/main.xml

标签:protect   emc   switch   apk   XML   flat   over   save   ase   

原文地址:http://www.cnblogs.com/lhang55/p/6537081.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!