BottomSheetDialogFragment view becomes transparent only after device rotation










0















I want to create BottomSheetDialogFragment with rounded corners.



What I've done to achieve that:



 <style name="AppTheme.TransparentBottomSheetStyle" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="android:background">@android:color/transparent</item>
</style>

<style name="AppTheme.BottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.Dialog">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:colorBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="bottomSheetStyle">@style/AppTheme.TransparentBottomSheetStyle</item>
</style>


backdrop_shape.xml:



<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="#00FF00"/>

<corners
android:topLeftRadius="24dp"
android:topRightRadius="24dp"/>
</shape>


And bottom sheet layout:



<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backdrop_shape"
android:paddingBottom="18dp">


And code:



override fun onActivityCreated(savedInstanceState: Bundle?) 
super.onActivityCreated(savedInstanceState)
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme)
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)



This works fine with AppCompat theme, but not with MaterialComponents:



enter image description here



As you can see, there is white background (I think, it's parent FrameLayout with id design_bottom_sheet).



And most interesting thing is that when I rotate the device (and then rotate it back), it becomes transparent as I wanted:



enter image description here



Is it bug or feature? How to fix it?



Note: I've tried all the solutions, that were posted on SO and other websites, they do not work on MaterialComponents too.










share|improve this question






















  • Could you try moving setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme) and dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) to onCreate instead of onActivityCreated?

    – Aaron
    Nov 15 '18 at 1:23











  • @Aaron that worked, thanks. But clearFlags should be in onActivityCreated, or it would not work. Can you please post it as answer? I will accept it.

    – arts777
    Nov 15 '18 at 11:20











  • Brilliant, thanks!

    – Aaron
    Nov 15 '18 at 11:37
















0















I want to create BottomSheetDialogFragment with rounded corners.



What I've done to achieve that:



 <style name="AppTheme.TransparentBottomSheetStyle" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="android:background">@android:color/transparent</item>
</style>

<style name="AppTheme.BottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.Dialog">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:colorBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="bottomSheetStyle">@style/AppTheme.TransparentBottomSheetStyle</item>
</style>


backdrop_shape.xml:



<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="#00FF00"/>

<corners
android:topLeftRadius="24dp"
android:topRightRadius="24dp"/>
</shape>


And bottom sheet layout:



<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backdrop_shape"
android:paddingBottom="18dp">


And code:



override fun onActivityCreated(savedInstanceState: Bundle?) 
super.onActivityCreated(savedInstanceState)
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme)
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)



This works fine with AppCompat theme, but not with MaterialComponents:



enter image description here



As you can see, there is white background (I think, it's parent FrameLayout with id design_bottom_sheet).



And most interesting thing is that when I rotate the device (and then rotate it back), it becomes transparent as I wanted:



enter image description here



Is it bug or feature? How to fix it?



Note: I've tried all the solutions, that were posted on SO and other websites, they do not work on MaterialComponents too.










share|improve this question






















  • Could you try moving setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme) and dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) to onCreate instead of onActivityCreated?

    – Aaron
    Nov 15 '18 at 1:23











  • @Aaron that worked, thanks. But clearFlags should be in onActivityCreated, or it would not work. Can you please post it as answer? I will accept it.

    – arts777
    Nov 15 '18 at 11:20











  • Brilliant, thanks!

    – Aaron
    Nov 15 '18 at 11:37














0












0








0








I want to create BottomSheetDialogFragment with rounded corners.



What I've done to achieve that:



 <style name="AppTheme.TransparentBottomSheetStyle" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="android:background">@android:color/transparent</item>
</style>

<style name="AppTheme.BottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.Dialog">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:colorBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="bottomSheetStyle">@style/AppTheme.TransparentBottomSheetStyle</item>
</style>


backdrop_shape.xml:



<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="#00FF00"/>

<corners
android:topLeftRadius="24dp"
android:topRightRadius="24dp"/>
</shape>


And bottom sheet layout:



<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backdrop_shape"
android:paddingBottom="18dp">


And code:



override fun onActivityCreated(savedInstanceState: Bundle?) 
super.onActivityCreated(savedInstanceState)
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme)
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)



This works fine with AppCompat theme, but not with MaterialComponents:



enter image description here



As you can see, there is white background (I think, it's parent FrameLayout with id design_bottom_sheet).



And most interesting thing is that when I rotate the device (and then rotate it back), it becomes transparent as I wanted:



enter image description here



Is it bug or feature? How to fix it?



Note: I've tried all the solutions, that were posted on SO and other websites, they do not work on MaterialComponents too.










share|improve this question














I want to create BottomSheetDialogFragment with rounded corners.



What I've done to achieve that:



 <style name="AppTheme.TransparentBottomSheetStyle" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="android:background">@android:color/transparent</item>
</style>

<style name="AppTheme.BottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.Dialog">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:colorBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="bottomSheetStyle">@style/AppTheme.TransparentBottomSheetStyle</item>
</style>


backdrop_shape.xml:



<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="#00FF00"/>

<corners
android:topLeftRadius="24dp"
android:topRightRadius="24dp"/>
</shape>


And bottom sheet layout:



<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backdrop_shape"
android:paddingBottom="18dp">


And code:



override fun onActivityCreated(savedInstanceState: Bundle?) 
super.onActivityCreated(savedInstanceState)
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme)
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)



This works fine with AppCompat theme, but not with MaterialComponents:



enter image description here



As you can see, there is white background (I think, it's parent FrameLayout with id design_bottom_sheet).



And most interesting thing is that when I rotate the device (and then rotate it back), it becomes transparent as I wanted:



enter image description here



Is it bug or feature? How to fix it?



Note: I've tried all the solutions, that were posted on SO and other websites, they do not work on MaterialComponents too.







android material-design android-design-library material-components-android






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 23:17









arts777arts777

5,4342778141




5,4342778141












  • Could you try moving setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme) and dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) to onCreate instead of onActivityCreated?

    – Aaron
    Nov 15 '18 at 1:23











  • @Aaron that worked, thanks. But clearFlags should be in onActivityCreated, or it would not work. Can you please post it as answer? I will accept it.

    – arts777
    Nov 15 '18 at 11:20











  • Brilliant, thanks!

    – Aaron
    Nov 15 '18 at 11:37


















  • Could you try moving setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme) and dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) to onCreate instead of onActivityCreated?

    – Aaron
    Nov 15 '18 at 1:23











  • @Aaron that worked, thanks. But clearFlags should be in onActivityCreated, or it would not work. Can you please post it as answer? I will accept it.

    – arts777
    Nov 15 '18 at 11:20











  • Brilliant, thanks!

    – Aaron
    Nov 15 '18 at 11:37

















Could you try moving setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme) and dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) to onCreate instead of onActivityCreated?

– Aaron
Nov 15 '18 at 1:23





Could you try moving setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme) and dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) to onCreate instead of onActivityCreated?

– Aaron
Nov 15 '18 at 1:23













@Aaron that worked, thanks. But clearFlags should be in onActivityCreated, or it would not work. Can you please post it as answer? I will accept it.

– arts777
Nov 15 '18 at 11:20





@Aaron that worked, thanks. But clearFlags should be in onActivityCreated, or it would not work. Can you please post it as answer? I will accept it.

– arts777
Nov 15 '18 at 11:20













Brilliant, thanks!

– Aaron
Nov 15 '18 at 11:37






Brilliant, thanks!

– Aaron
Nov 15 '18 at 11:37













1 Answer
1






active

oldest

votes


















1














According to DialogFragment.setStyle:




Call to customize the basic appearance and behavior of the fragment's
dialog. This can be used for some common dialog behaviors, taking care
of selecting flags, theme, and other options for you. The same effect
can be achieve by manually setting Dialog and Window attributes
yourself. Calling this after the fragment's Dialog is created will
have no effect.




I'm guessing that maybe setStyle should be called in or before onCreate.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310205%2fbottomsheetdialogfragment-view-becomes-transparent-only-after-device-rotation%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    According to DialogFragment.setStyle:




    Call to customize the basic appearance and behavior of the fragment's
    dialog. This can be used for some common dialog behaviors, taking care
    of selecting flags, theme, and other options for you. The same effect
    can be achieve by manually setting Dialog and Window attributes
    yourself. Calling this after the fragment's Dialog is created will
    have no effect.




    I'm guessing that maybe setStyle should be called in or before onCreate.






    share|improve this answer





























      1














      According to DialogFragment.setStyle:




      Call to customize the basic appearance and behavior of the fragment's
      dialog. This can be used for some common dialog behaviors, taking care
      of selecting flags, theme, and other options for you. The same effect
      can be achieve by manually setting Dialog and Window attributes
      yourself. Calling this after the fragment's Dialog is created will
      have no effect.




      I'm guessing that maybe setStyle should be called in or before onCreate.






      share|improve this answer



























        1












        1








        1







        According to DialogFragment.setStyle:




        Call to customize the basic appearance and behavior of the fragment's
        dialog. This can be used for some common dialog behaviors, taking care
        of selecting flags, theme, and other options for you. The same effect
        can be achieve by manually setting Dialog and Window attributes
        yourself. Calling this after the fragment's Dialog is created will
        have no effect.




        I'm guessing that maybe setStyle should be called in or before onCreate.






        share|improve this answer















        According to DialogFragment.setStyle:




        Call to customize the basic appearance and behavior of the fragment's
        dialog. This can be used for some common dialog behaviors, taking care
        of selecting flags, theme, and other options for you. The same effect
        can be achieve by manually setting Dialog and Window attributes
        yourself. Calling this after the fragment's Dialog is created will
        have no effect.




        I'm guessing that maybe setStyle should be called in or before onCreate.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 15 '18 at 11:39









        arts777

        5,4342778141




        5,4342778141










        answered Nov 15 '18 at 11:37









        AaronAaron

        1,7432212




        1,7432212





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310205%2fbottomsheetdialogfragment-view-becomes-transparent-only-after-device-rotation%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto