微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 避免PopupWindow在外面触摸后解雇

我想使用具有以下行为/功能的PopupWindow:

>它是可对焦的(在例如按钮之间具有交互式控件)
>“弹出窗口”下的“查看”必须正确地使用弹出窗口之外的触摸
> ..但弹出窗口必须留在屏幕上,即使在点击外面

我发现一些关于PopupWindow的帖子,但是没有人问到如何处理这种情况.

我想我尝试过setoutsidetouchable(),setFocusable(),setTouchable()的所有可能的组合,但是我被卡住了.弹出窗口正确处理点击,但在外面触摸时总是被忽略.

我当前的代码是:

View.OnTouchListener customPopUpTouchListenr = new View.OnTouchListener(){

    @Override
    public boolean onTouch(View arg0,MotionEvent arg1) {
        Log.d("POPUP","Touch false");
        return false;
    }

};


LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout= (LinearLayout)inflater.inflate(R.layout.insert_point_dialog,null);
PopupWindow pw = new PopupWindow(layout,400,200,true);
pw.setoutsidetouchable(true);
pw.setTouchable(true);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setTouchInterceptor(customPopUpTouchListenr);
pw.showAtLocation(frameLayout,Gravity.BottOM,0);

我的一般目标是创建一个浮动窗口,在像gimp这样的软件中表现得像一个“工具调色板”:内部有一些控件,保持在顶部,直到被“X”按钮关闭,并允许与外面的控件进行交互.
也许有更好的方法来做,而不是PopupWindow?但我还没有找到更合适的控制.

解决方法

只需删除pw.setBackgroundDrawable(新的BitmapDrawable());

原文地址:https://www.jb51.cc/android/310625.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐