常用控件(一):PopWindow ,提示框,阴影线

弹出popwindow


private void initListView() {
		listView = new ListView(this);
		listView.setBackgroundResource(R.drawable.listview_background); //设置listView 背景
		listView.setDivider(null);	//设置条目之间的分隔线为null
		listView.setVerticalScrollBarEnabled(false); // 关闭
		
		listView.setAdapter(new MyListAdapter());
	}


downArrow.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				System.out.println("=======");
				//定义 popupWindow
				popWin = new PopupWindow(MainActivity.this);
				popWin.setWidth(input.getWidth()); //设置宽度
				popWin.setHeight(200);	//设置popWin 高度
				
				popWin.setContentView(listView); //为popWindow填充内容
				popWin.setOutsideTouchable(true); // 点击popWin 以处的区域,自动关闭 popWin
				
				popWin.showAsDropDown(input, 0, 0);//设置 弹出窗口,显示的位置
				
			}
		});


进度提示框
public void showProgressBar(String message) {
if (progressDialog != null && progressDialog.isShowing()) {
return;
}
// progressDialog.setMessage(message);
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(true);// 点击进度条以外的部分也锁屏
progressDialog.show();
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.pg, null);
Window window = progressDialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
// 设置透明度为0.3
lp.alpha = 1.0f;
lp.dimAmount = 0.0f;
lp.gravity = Gravity.CENTER;
window.setAttributes(lp);
window.setContentView(v);
progressDialog.setOnKeyListener(MyKeyListener);
}

public void stopWaitBar() {
if (progressDialog != null) {
progressDialog.dismiss();
}
} 




    


线:


 


--------------------------------------------------------------------------------------------------

弹出一个popwindow :

点击 外部可以消失

点击返回键可以消失

/**
     * 图片上传popupwindow
     */
    public static class MyPopupWindow extends PopupWindow {

        public MyPopupWindow(Context mContext, View parent) {

            View view = View.inflate(mContext, R.layout.activity_giftmoney_share_popwindow, null);
            view.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.fade_ins));
            LinearLayout ll_popup = (LinearLayout) view.findViewById(R.id.line_popup);
            ll_popup.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.push_bottom));
            // 设置宽高
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
            setHeight(400);
            //设置一个默认背景图
            setBackgroundDrawable(new BitmapDrawable());
            //设置外部可以点击关闭
            setOutsideTouchable(true);
            //设置点击返回键可以关闭
            setFocusable(true);
            //设置布局文件
            setContentView(view);
            TextView takpe_tv = (TextView) view.findViewById(R.id.takpe_tv);
            TextView select_tv = (TextView) view.findViewById(R.id.select_tv);
            TextView btn_cancel = (TextView) view.findViewById(R.id.btn_cancel);
            takpe_tv.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    weixin();
                    dismiss();
                }
            });
            select_tv.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    phone();
                    dismiss();
                }
            });
            btn_cancel.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    dismiss();
                }
            });
        }

        public void weixin() {
        }

        

        public void phone() {
        }

        // 点击外部关闭
view.setOnClickListener(new View.OnClickListener() {
 
   
    @Override
 
   
    public void onClick(View v) {
 
   
        dismiss();
 
   
    }
 
   
});
 
  
    }


onclick:

new MyPopupWindow(this, recyclerview).showAtLocation(this.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
recyclerview 参数没用







你可能感兴趣的:(UI)