我用 mspaint 制定的方案最好地解释了我想要实现的目标:
![enter image description here](https://i.stack.imgur.com/SEcdE.jpg)
我尝试过设置FLAG_NOT_TOUCH_MODAL
根据描述,这应该正是我想要的,但它根本不起作用。我的活动消耗ALL触摸事件,甚至在其边界之外。
如果我设置FLAG_NOT_FOCUSABLE
当然,该活动下的本机控件是可触摸的,但是即使在触摸其边框内部时,该活动也完全不可触摸。
我尝试过设置isFloatingWindow=true
在清单中,但似乎没有任何区别。
任何人都可以实现这一点吗?我真的很感激一个以这种方式工作的小型演示活动,这样我就可以接受它并从那里开始工作。我已经尝试了 WindowManager 和 Intent 标志的多种排列,但似乎没有什么能完全按照我的需要工作。
提前致谢。
UPDATE:
我已经尝试过你的建议,但它仍然没有达到预期效果。
这是我的活动布局 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
class:
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](https://i.stack.imgur.com/BzSez.png)
我缺少什么?
Thanks.
Set a Dialog
主题于Activity
在你的清单中。例如:
android:theme="@android:style/Theme.Dialog"
然后设置如下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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)