如何创建仍然允许触摸其边界外的本机控件的浮动可触摸活动?

Nom*_*fan 6 android floating android-activity

我试图实现的目标最好用我用mspaint制作的方案来解释:

在此输入图像描述

我试图设置FLAG_NOT_TOUCH_MODAL哪个描述应该是我想要的,但它根本不起作用.我的活动消耗所有触摸事件,甚至在其边界之外.

如果我设置FLAG_NOT_FOCUSABLE当然活动下的本机控件是可触摸的,但是当触摸其边界内时活动完全不均匀.

我试过设置isFloatingWindow=true清单,但似乎没有任何区别.

谁能实现这个目标?我非常感谢以这种方式工作的小型演示活动,因此我可以从那里开始工作.我已经尝试了很多WindowManager和Intent标志的排列,似乎没有任何东西可以完全按照我的需要工作.

提前致谢.

更新:

我已经尝试了你的建议,但它仍然无法正常工作.

这是我的活动布局xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="385dp"
android:layout_height="300dp"
android:theme="@android:style/Theme.Dialog"
tools:context="com.ui.activities.TestActivity"
android:id="@+id/testLayout"
android:visibility="visible"
android:background="@drawable/abc_ab_solid_light_holo"
android:clickable="true">

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Click me"
    android:id="@+id/button"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="35dp"
    android:clickable="true"
    android:enabled="true"
    android:onClick="onClick" />
Run Code Online (Sandbox Code Playgroud)

这是Activity班级:

public class TestActivity extends Activity implements View.OnClickListener {

private String TAG = TestActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);

    setWindowParams();
}

private void setWindowParams() {
    WindowManager.LayoutParams wlp = getWindow().getAttributes();
    wlp.dimAmount = 0;
    wlp.flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    getWindow().setAttributes(wlp);
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这是结果:

看起来不像是一个对话框

我错过了什么?

谢谢.

Mik*_* M. 9

在清单中设置Dialog主题Activity.例如:

android:theme="@android:style/Theme.Dialog"
Run Code Online (Sandbox Code Playgroud)

然后在以下位置设置以下Window参数onCreate():

public void setWindowParams() {
    WindowManager.LayoutParams wlp = getWindow().getAttributes();
    wlp.dimAmount = 0;            
    wlp.flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    getWindow().setAttributes(wlp);     
}
Run Code Online (Sandbox Code Playgroud)