gpt4 book ai didi

android - 如何创建仍然允许触摸其边界外的 native 控件的 float 可触摸 Activity ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:42:59 25 4
gpt4 key购买 nike

我用 mspaint 制作的方案最好地解释了我想要实现的目标:

enter image description here

我已经尝试设置 FLAG_NOT_TOUCH_MODAL,根据描述,这应该正是我想要的,但它根本不起作用。我的 Activity 消耗了 ALL 触摸事件,即使在其边界之外也是如此。

如果我设置了 FLAG_NOT_FOCUSABLE 那么 Activity 下的 native 控件当然是可触摸的,但是即使在其边界内触摸时 Activity 也完全不可触摸。

我已经尝试在 list 中设置 isFloatingWindow=true,但似乎没有任何区别。

有人能做到吗?我真的很感激一个以这种方式工作的小型演示 Activity ,这样我就可以接受它并从那里开始工作。我已经尝试了 WindowManager 和 Intent 标志的多种排列,但似乎没有任何东西能完全按照我的需要工作。

提前致谢。

更新:

我已经尝试了您的建议,但仍然没有达到预期的效果。

这是我的 Activity 布局 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" />

这是 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);
}

不幸的是,这是结果:

Does not look like a dialog

我错过了什么?

谢谢。

最佳答案

在 list 中的 Activity 上设置一个 Dialog 主题。例如:

android:theme="@android:style/Theme.Dialog"

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

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);
}

关于android - 如何创建仍然允许触摸其边界外的 native 控件的 float 可触摸 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33853311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com