BottomSheetDialogFragment view becomes transparent only after device rotation
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
:
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:
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
add a comment |
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
:
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:
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
Could you try movingsetStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme)
anddialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
toonCreate
instead ofonActivityCreated
?
– Aaron
Nov 15 '18 at 1:23
@Aaron that worked, thanks. ButclearFlags
should be inonActivityCreated
, 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
add a comment |
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
:
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:
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
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
:
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:
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
android material-design android-design-library material-components-android
asked Nov 14 '18 at 23:17
arts777arts777
5,4792778142
5,4792778142
Could you try movingsetStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme)
anddialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
toonCreate
instead ofonActivityCreated
?
– Aaron
Nov 15 '18 at 1:23
@Aaron that worked, thanks. ButclearFlags
should be inonActivityCreated
, 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
add a comment |
Could you try movingsetStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme)
anddialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
toonCreate
instead ofonActivityCreated
?
– Aaron
Nov 15 '18 at 1:23
@Aaron that worked, thanks. ButclearFlags
should be inonActivityCreated
, 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
add a comment |
1 Answer
1
active
oldest
votes
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
.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
.
add a comment |
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
.
add a comment |
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
.
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
.
edited Nov 15 '18 at 11:39
arts777
5,4792778142
5,4792778142
answered Nov 15 '18 at 11:37
AaronAaron
1,8282213
1,8282213
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Could you try moving
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.AppTheme_BottomSheetDialogTheme)
anddialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
toonCreate
instead ofonActivityCreated
?– Aaron
Nov 15 '18 at 1:23
@Aaron that worked, thanks. But
clearFlags
should be inonActivityCreated
, 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