zoukankan      html  css  js  c++  java
  • android 为组件添加contextMenu上下文菜单

    package com.example.fragmentNavigation2.fragment;
    
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.*;
    import android.widget.Button;
    import android.widget.Toast;
    import com.example.fragmentNavigation2.R;
    
    public class WeiXinFragment extends Fragment {
    
        private Button button;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.wei_xin_fragment, container, false);
            button = (Button) view.findViewById(R.id.press_button);
            registerForContextMenu(button);
            return view;
        }
    
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            new MenuInflater(getActivity()).inflate(R.menu.context_menu, menu);
            menu.setHeaderTitle("请选择你喜欢的网站");
            super.onCreateContextMenu(menu, v, menuInfo);
        }
    
        /**
         * 相应本fragment对应的上下文菜单事件
         */
        @Override
        public boolean onContextItemSelected(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.first_item:
                    Toast.makeText(getActivity(), "重庆国际矿产开发协会", 1).show();
                    break;
                case R.id.second_item:
                    Toast.makeText(getActivity(), "重庆雨人网络工作室", 1).show();
                    break;
            }
            return true;
        }
    }
    <?xml version="1.0" encoding="utf-8"?>
    
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
            <item android:id="@+id/first_item" android:title="第一个选项"></item>
            <item android:id="@+id/second_item" android:title="第二个选项"></item>
            <item android:title="第三个选项"></item>
    </menu>
  • 相关阅读:
    net-speeder 安装
    CentOS 5/6 下添加epel源
    让进程在后台可靠运行的几种方法
    学习supervisor
    SQLAlchemy tutorial
    Ubuntu包管理工具整理
    Photoshop保存文件时的选项
    python反射
    python包管理(distutils、easy_install、pip、setup.py/requirements.txt、wheel)
    python 一句话输出26个英文字母
  • 原文地址:https://www.cnblogs.com/wuyou/p/3525664.html
Copyright © 2011-2022 走看看