How to create a floating touchable activity that still allows to touch native controls outside of its borders?

China☆狼群 提交于 2019-11-30 09:49:40

Set a Dialog theme on the Activity in your manifest. For example:

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

Then set the following Window parameters in 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);     
}

You can use activity with special theme in your AndroidManifest file:

<style name="Theme.Transparent">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowContentOverlay">@null</item>
        <!--<item name="android:backgroundDimEnabled">false</item>--> // show/hide background 
        <item name="android:windowIsFloating">true</item>
</style>

And also don't forget to set mach_parent attribute in Activity like:

override fun onStart() {
        super.onStart()
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!