关闭

android弹出窗口实现

标签: android
252人阅读 评论(0) 收藏 举报
分类:
/**
      * popWindow(下拉列表弹出)
      * @Title: popWindow
      * @param     设定文件
      * @return void    返回类型
      */
    
    private void popWindow()
    {
        
        int intMobilePhoneWidth = WindowSizeUtil.getWidth(mContext);
        int intMobilePhoneHeight = WindowSizeUtil.getHeight(mContext);
        
        int popWidth = (int) (intMobilePhoneWidth / 4); //6.40
        int popHeight = (int) (intMobilePhoneHeight / 7);//5.80  //15.4

        
        LayoutInflater flater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        popWindowView = flater.inflate(R.layout.common_listview, null);
        popWindowView.setBackgroundColor(Color.GRAY);
        popWindowView.setAlpha(255);// 0~255透明度值
        
        
        lv_popup = (ListView) popWindowView.findViewById(R.id.lv_common);
        
        ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String,String>>();
        HashMap<String, String > obj =new HashMap<String, String>();
        obj.put("id","jubao");
        obj.put("name", "举报");
        list.add(obj );
        
        HashMap<String, String > obj1 =new HashMap<String, String>();
        obj1.put("id","fuzhi");
        obj1.put("name", "复制链接");
        list.add(obj1 );
        
        NgPopWindowAdapter adapter = new NgPopWindowAdapter(mContext, list);
        lv_popup.setAdapter(adapter);
        
        popwindow = new PopupWindow(popWindowView,popWidth,popHeight);
        popwindow.showAsDropDown(btn_jubao);
        // 使其聚集
        popwindow.setFocusable(true);
        // 设置允许在外点击消失
        popwindow.setOutsideTouchable(true);

        // 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
        popwindow.setBackgroundDrawable(new BitmapDrawable());
        
        
        lv_popup.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                
                
                Intent intent = new Intent(mContext, ReportActivity.class);
                
                if(nGArticleBean!=null){
                    intent.putExtra(ProjectConstant.INTENT_EXTRA_FRIEND_UCODE, nGArticleBean.getUserCode());
                }
                mContext.startActivity(intent);

                
            }
            
        });
        
    }


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:63541次
    • 积分:991
    • 等级:
    • 排名:千里之外
    • 原创:34篇
    • 转载:16篇
    • 译文:0篇
    • 评论:16条
    公众号

    欢迎关注公众号


    文章分类
    最新评论