Calling Android Dialog Without It Fading the Background

Calling android dialog without it fading the background

Create a res/values/styles.xml file and add this to it.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.DoNotDim" parent="android:Theme">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>

And apply the theme to your activity.

<activity android:name=".SampleActivity" android:theme="@style/Theme.DoNotDim">

How to remove transparent dark background outside of dialog box

Your question has already been answered here

Code from the link:

Add this to your styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.DoNotDim" parent="android:Theme">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>

And then apply the theme to your activity:

<activity android:name=".SampleActivity" android:theme="@style/Theme.DoNotDim">

Custom dialog not showing, just faded black background

The issue is arising due to the fact that you are not giving it any style.

Use  infoDialog.setView(view)

And while creating dialogbox give a material theme style

val infoDialog = AlertDialog.Builder(ContextThemeWrapper(context,android.R.style.ThemeOverlay_Material_Dialog)).create()

and in the end

infoDialog.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
infoDialog.show()

Rest of your code is fine.

Prevent Android activity dialog from closing on outside touch

This could help you. It is a way to handle the touch outside event:

How to cancel an Dialog themed like Activity when touched outside the window?

By catching the event and doing nothing, I think you can prevent the closing. But what is strange though, is that the default behavior of your activity dialog should be not to close itself when you touch outside.

(PS: the code uses WindowManager.LayoutParams)



Related Topics



Leave a reply



Submit