Calling android dialog without it fading the background

前端 未结 4 548
花落未央
花落未央 2020-11-29 02:08

I have this nice dialog view I set my UserInputDialog class to:

    

        
相关标签:
4条回答
  • 2020-11-29 02:53

    For displaying dialog like TrueCaller do this:

    In styles.xml file.

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

    In AndroidManifest.xml do this:

    <activity android:name=".SampleActivity" android:theme="@style/myBackgroundStyle">
    
    0 讨论(0)
  • 2020-11-29 02:57

    You can also remove the dim effect by code with the following:

    dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    
    0 讨论(0)
  • 2020-11-29 03:00

    Create a custom style and place it in your values folder

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

    To set a style to an individual dialog you can use

    Dialog dialog = new Dialog(context, R.style.YourCustomStyle);
    
    0 讨论(0)
  • 2020-11-29 03:02

    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">
    
    0 讨论(0)
提交回复
热议问题