前言:有一个需求需要点击dialog外面要消失,本来以为很简单结果设置了一直未生效
setCanceledOnTouchOutside(true);
问了半天chat-gpt4结果给的答案都不明显

查看代码发现设置了style,于是尝试去除这个style,结果点击setCanceledOnTouchOutside(true);生效了
<style name="LionCommonDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.5</item>
</style>
经过排比法,发现是<item name="android:windowIsTranslucent">true</item>导致的

Chatgpt说他会影响触摸事件,终于真相大白了!!!!