Android开发之自定义PopupWindow记录
16lz
2022-01-24
1、继承PopupWindow :package com.qy.foreign_trade.dialog;import android.app.Activity;import android.content.Context;import android.graphics.drawable.ColorDrawable;import android.view.View;import android.view.ViewGroup;import android.view.WindowManager;import android.widget.PopupWindow;import com.qy.foreign_trade.R;/** * Created by xu_xin on 2019/7/3 0003. */public class XPopupWindow1 extends PopupWindow { private WindowManager.LayoutParams lp; private Activity mContext; private View contentView; public XPopupWindow1(Context context) { mContext = (Activity) context; lp = mContext.getWindow().getAttributes(); setContentView(init()); setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { setAlpha(1f); } }); } public View getContentView() { return contentView; } private View init() { contentView = View.inflate(mContext, R.layout.pop_tips, null); setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); setBackgroundDrawable(new ColorDrawable(0x00FFFFFF)); setFocusable(false); setOutsideTouchable(false); return contentView; } @Override public void showAtLocation(View parent, int gravity, int x, int y) { setAlpha(0.7f); super.showAtLocation(parent, gravity, x, y); } @Override public void showAsDropDown(View anchor) { setAlpha(0.7f); super.showAsDropDown(anchor); } private void setAlpha(float alpha) { lp.alpha = alpha; mContext.getWindow().setAttributes(lp); }}
2、使用
private void sureBack() {popupWindow = new XPopupWindow1(this.mContext);View contentView = popupWindow.getContentView();popupWindow.showAtLocation(contentView, Gravity.CENTER, 0, 0);TextView tv_state_name = contentView.findViewById(R.id.tv_state_name);TextView tv_tips = contentView.findViewById(R.id.tv_tips);LinearLayout ll_hs = contentView.findViewById(R.id.ll_hs);TextView tv_cencel = contentView.findViewById(R.id.tv_cencel);TextView tv_suer = contentView.findViewById(R.id.tv_suer);}
完成
更多相关文章
- Windows下使用platform.pk8 和platform.x509.pem生成Android(安
- android skia 使用实例
- Android(安卓)使用内容解析者往短信数据库里插入一条数据
- android中shape的使用(android:angle小解)
- android 使用代码实现 RelativeLayout布局
- 【Android开发学习43】OpenGL ES教程VI之纹理贴图(原文对照)
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用