今天做项目的时候碰到需要弹窗的部分,感觉这种已定义弹窗很好用。效果图:
主体代码:
//点击返回键弹框 final AlertDialog.Builder builder = new AlertDialog.Builder(context); final View view = LayoutInflater.from(context).inflate(R.layout.shopping_xuqiu_popwindow, null); final AlertDialog dialog=builder.setView(view).show(); //通过LayoutInflater来加载一个xml的布局文件作为一个View对象 Button finishBT=(Button)view.findViewById(R.id.finishBT); finishBT.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //view.setVisibility(View.GONE); dialog.dismiss(); } });layout代码:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width=