弹出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();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
style="@android:style/Widget.ProgressBar.Large.Inverse"
android:layout_width="30dip"
android:layout_height="30dip"
/>
</LinearLayout>
线:
<TextView android:layout_width="fill_parent"
android:id="@id/xct_lthj_page_query_mainframe_line_up"
android:layout_height="@dimen/xct_lthj_space_zeroone" />
<TextView android:layout_width="fill_parent"
android:id="@id/xct_lthj_page_query_mainframe_line_down"
android:layout_height="@dimen/xct_lthj_space_zeroone" />
--------------------------------------------------------------------------------------------------
弹出一个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() {
}
// 点击外部关闭
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:11.3pt;">view.setOnClickListener(<span style="color:#cc7832;">new </span>View.OnClickListener() {
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:11.3pt;"> <span style="color:#bbb529;">@Override </span>
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:11.3pt;"><span style="color:#bbb529;"> </span><span style="color:#cc7832;">public void </span><span style="color:#ffc66d;">onClick</span>(View v) {
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:11.3pt;"> dismiss()<span style="color:#cc7832;">; </span>
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:11.3pt;"><span style="color:#cc7832;"> </span>}
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:11.3pt;">})<span style="color:#cc7832;">;</span>
}
onclick:
new MyPopupWindow(this, recyclerview).showAtLocation(this.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
recyclerview 参数没用