作者:手机用户2602914627 | 来源:互联网 | 2023-10-10 08:41
PopupWindow
效果图
代码
layout_pop.xml
PopupWindowActivity
public class PopupWindowActivity extends AppCompatActivity {
private Button mBtnPop;
private PopupWindow mPop;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_popup_window);
mBtnPop = findViewById(R.id.btn_pop);
mBtnPop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View view = getLayoutInflater().inflate(R.layout.layout_pop, null);
TextView tv = view.findViewById(R.id.tv_good);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPop.dismiss();
ToastUtil.showLong(PopupWindowActivity.this, ((TextView)v).getText());
}
});
mPop = new PopupWindow(view, mBtnPop.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
mPop.setOutsideTouchable(false);
mPop.setFocusable(true);
mPop.showAsDropDown(mBtnPop);
}
});
}
}