资 源 简 介
Android Custom Menu 弹出窗口式自定义菜单栏的实例源码,运行后通过轻触手机的菜单键,来唤出菜单窗口,再次点击菜单键,自定义弹出对话框则隐藏,菜单是布局在对话框窗口中的,在本例中,自定义弹出窗口继承PopupWindow,并封装有封装GridView组件和View 组件,GridView 为每个Item设置监听事件方法,部分代码先睹为快:
public CustomMenu(Activity activity, List menus) {
super(activity);
//View 样式文件R.layout.menu
view = activity.getLayoutInflater().inflate(R.layout.menu, null);
//实例化GridView组件
gvMenu = (GridView)view.findViewById(R.id.gv_menu);
//相关参数设置
this.setContentView(view);
this.setWidth(LayoutParams.FILL_PARENT);
this.setHeight(LayoutParams.WRAP_CONTENT);
//图片获取
Drawable drawable = activity.getResources().getDrawable(R.drawable.selector_focused_shape);
//相关特效设置
this.setBackgroundDrawable(drawable);
this.setAnimationStyle(R.style.PopupAnimation);
this.setFocusable(true);
//设置相关OnKeyListener事件
gvMenu.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_MENU)&&(isShowing())) {
dismiss();//关闭P