Menu简介
Menu是
系统菜单
onCreateOptionsMenu
监听事件:onOptionsItemSelected
上下文菜单
AlertDialog.Builder()
监听事件:setSingleChoiceItems()
系统菜单
创建menu文件
layout文件
通过重写onCreateOptionsMenu和onOptionsItemSelected来实现menu
//重写onCreateOptionsMenu加载资源
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
//设置监听事件
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Toast.makeText(this, ""+item.getTitle(), Toast.LENGTH_SHORT).show();
return super.onOptionsItemSelected(item);
}
通过popuWindow实现
popu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupWindow popupWindow = new PopupWindow(MainActivity.this);
View inflate = LayoutInflater.from(MainActivity.this).inflate(R.layo