简单弹窗PopupWindow
//弹框t
PopupWindow popupWindow = new PopupWindow();
//宽高必须要有
popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
//点击外部取消
popupWindow.setOutsideTouchable(true);
//加载布局
View inflate = LayoutInflater.from(this).inflate(R.layout.popu, null);
popupWindow.setContentView(inflate);//设置布局
View activity_main = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
//在activity_main布局的最下
popupWindow.showAtLocation(activity_main, Gravity.BOTTOM,0,0);
//显示到某个控件的下边
//popupWindow.showAsDropDown(add);
//控件里的点击事件
inflate.findViewById(R.id.sao).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "hhhhhhh", Toast.LENGTH_SHORT).show();
}
});
控件里的点击事件:点击扫一扫,吐司:hhhhhhh
接下来就是布局文件
<TextView
android:id="@+id/sao"
android:textColor="#fff"
android:textSize="20sp"
android:gravity="center"
android:text="扫一扫"
android:layout_width="match_parent"
android:layout_height="match_parent" />