单击外部弹出窗口设置为false [setOutsideTouchable(false)]不起作用

编程入门 行业动态 更新时间:2024-10-15 02:31:29
本文介绍了单击外部弹出窗口设置为false [setOutsideTouchable(false)]不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

//创建layoutinflator 尝试{

//create layoutinflator try {

LayoutInflater inflator = LayoutInflater.from(this);

//创建视图

final View menuview = inflater.inflate(R.layout.menu, (ViewGroup) findViewById(R.layout.dictionarylist)); Button Menu = (Button) findViewById(R.id.Menu); Menu.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { final PopupWindow pw = new PopupWindow(menuview);//initialize popupwindow pw.showAtLocation(v, Gravity.CENTER, 0, 0); pw.update(0, 0, 200, 250); pw.setOutsideTouchable(false);//set outside touch to false

//onclick侦听器,用于popupwindow中的按钮

//onclick listener for the button inside popupwindow

Button b1 = (Button) menuview.findViewById(R.id.btnClose); b1.setOnClickListener(new OnClickListener() { // @Override public void onClick(View v) { pw.dismiss(); } }); Button b2 = (Button) menuview.findViewById(R.id.btnQuiz); b2.setOnClickListener(new OnClickListener() { // @Override public void onClick(View v) { } }); Button b3 = (Button) menuview.findViewById(R.id.btnTopic); b3.setOnClickListener(new OnClickListener() { // @Override public void onClick(View v) { InitialTask2 Task1 = new InitialTask2(); Task1.execute(); } }); Button b4 = (Button) menuview .findViewById(R.id.btnDictionarylist); b4.setOnClickListener(new OnClickListener() { // @Override public void onClick(View v) { try{ if(getApplication() != null){ pw.dismiss(); } else{ Intent i = new Intent(); i.setClass(getBaseContext(), Dictionarylist.class); startActivity(i); } } catch(Exception x){ x.getMessage(); } } }); } }); } catch (Exception e) { e.getMessage(); } }

单击外部的弹出窗口不起作用pw.setOutsideTouchable(false);.在弹出窗口外单击时,它会执行放置在弹出窗口(即父窗口)后面的操作.

popup window outside click does not work pw.setOutsideTouchable(false);. When clicking outside the popup window it perform action placed behind the popup window i.e parent window.

推荐答案

尝试一下:

pw.setTouchable(true); pw.setFocusable(false); pw.setOutsideTouchable(false);

当窗口可触摸为true时,可聚焦为false时,setOutsideTouchable()起作用.

When window touchable is true, focusable is false, setOutsideTouchable() works.

如果为setOutsideTouchable(true),则将关闭popupwindow外部的触摸,否则弹出窗口的外部仍可被触摸而无需关闭.

If setOutsideTouchable(true), touch outside of popupwindow will dismiss, otherwise the outside of popupwindows still can be touchable without dismiss.

更多推荐

单击外部弹出窗口设置为false [setOutsideTouchable(false)]不起作用

本文发布于:2023-11-24 01:14:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623433.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   单击   弹出窗口   不起作用   false

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!