Hi can someone help me with styling dialog that appears after clicking on MediaRouteButton?
There is a white text displayed on gray background which doesn't look good.
android.support.v7.app.MediaRouteButton
is wrapped in parent with styles
<FrameLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:popupTheme="#style/ThemeOverlay.AppCompat.Dark"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
(I know that I should use Toolbar here but it doesn't match my requirements)
which works good on MediaRouteButton which turns white, but it have no influence on dialog styles.
I tried to look at sample app provided by Google, but I haven't found anything that helps me. Link to sample app styles
My current theme:
<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>//Blue
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>//dark blue
<item name="colorAccent">#color/colorPrimary</item>//blue
</style>
Found a solution that worked for me.
At first you have to set a custom MediaRouteDialogFactory on your MediaRouteButton
mMediaRouteMenuItem = CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item);
MediaRouteButton mediaRouteButton = (MediaRouteButton) mMediaRouteMenuItem.getActionView()
mediaRouteButton.setDialogFactory(new ThemeableMediaRouteDialogFactory());
Cause the default MediaRouteDialogFactory will always create non themed Dialogs
#NonNull
public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
return new MediaRouteControllerDialogFragment();
}
which will lead to
public MediaRouteControllerDialog onCreateControllerDialog(
Context context, Bundle savedInstanceState) {
return new MediaRouteControllerDialog(context);
}
but there is also a themed constructor MediaRouteControllerDialog(Context context, int theme)
which is not called from original MediaRouteDialogFactory.
So your ThemeableMediaRouteDialogFactory should be look like this
public class ThemeableMediaRouteDialogFactory extends MediaRouteDialogFactory {
#NonNull
#Override
public MediaRouteChooserDialogFragment onCreateChooserDialogFragment() {
return new ThemeableMediaRouterChooserDialogFragment();
}
#NonNull
#Override
public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
return new ThemeableMediaRouteControllerDialogFragment();
}
}
with
public class ThemeableMediaRouterChooserDialogFragment extends MediaRouteChooserDialogFragment {
#Override
public MediaRouteChooserDialog onCreateChooserDialog(Context context, Bundle savedInstanceState) {
return new MediaRouteChooserDialog(context, R.style.CastChooserDialogTheme);
}
}
and
public class ThemeableMediaRouteControllerDialogFragment extends MediaRouteControllerDialogFragment {
#Override
public MediaRouteControllerDialog onCreateControllerDialog(Context context, Bundle savedInstanceState) {
return new MediaRouteControllerDialog(context, R.style.CastControllerDialogTheme);
}
}
Your themes/styles can also be customized
<style name="DarkDialogTheme" parent="Theme.AppCompat.Dialog">
<item name="colorPrimary">#color/charcoal_grey</item>
<item name="colorPrimaryDark">#color/charcoal_grey_dark</item>
<item name="colorAccent">#color/pumpkin_orange</item>
<item name="android:windowBackground">#color/dark_grey</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="CastChooserDialogTheme" parent="DarkDialogTheme">
<item name="android:windowNoTitle">false</item>
<item name="mediaRouteChooserPrimaryTextStyle">#style/MediaRouteChooserPrimaryText</item>
<item name="mediaRouteChooserSecondaryTextStyle">#style/MediaRouteChooserSecondaryText</item>
</style>
<style name="CastControllerDialogTheme" parent="DarkDialogTheme">
<item name="MediaRouteControllerWindowBackground">#color/dark_grey</item>
<item name="colorPrimary">#color/dark_grey</item>
<item name="mediaRouteCloseDrawable">#drawable/ic_dialog_close_dark</item>
<item name="mediaRouteControllerTitleTextStyle">#style/Widget.MediaRouter.ControllerText.Title.Dark</item>
</style>
Related
I'm using dialog fragment. The problem is that the status bar color is changed to black. How to change it to some other color? It's strange cause inside fragment, activity it works fine. Its only black inside DialogFragment
#Override
public void onStart() {
super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point
Dialog d = getDialog();
if (d != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
d.getWindow().setLayout(width, height);
d.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dialog = new Dialog(getActivity(), R.style.full_screen_dialog);
return dialog;
}
You have to set FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDSto indicate that this Window is responsible for drawing the background for the system bars.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
dialog.getWindow().setStatusBarColor(yourColor);
}
I just posted the solution to this problem here
Add following theme to res/value-v21/style
<style name="DialogTheme" parent="#style/Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowTranslucentStatus">true</item>
</style>
And then apply Style on DialogFragment in onCreate
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.DialogTheme);
}
GUYS THE BEST SOLUTION IS IN THE WEBSITE LINK I AM POSTING HERE
https://zocada.com/android-full-screen-dialogs-using-dialogfragment/
I'll also upload the code here for reference
1st create a style FullScreenDialogStyle in your style file :
<style name="FullScreenDialogStyle" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorPrimary">#color/colorPrimary</item>
<!-- Set this to true if you want Full Screen without status bar -->
<item name="android:windowFullscreen">false</item>
<item name="android:windowIsFloating">false</item>
<!-- This is important! Don't forget to set window background -->
<item name="android:windowBackground">#color/colorWhite</item>
<!-- Additionally if you want animations when dialog opening -->
<!--<item name="android:windowEnterAnimation">#anim/slide_up</item>-->
<!--<item name="android:windowExitAnimation">#anim/slide_down</item>-->
</style>
inside your dialogFragment class override a method onCreate
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL,R.style.FullScreenDialogStyle);
}
then override Onstart method, through which u can access the getDialog() and set the height and width
#Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}
To change Status Bar Color under DialogFragment, set below style to your dialogFragment under onCreate Method.
like:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NO_TITLE,R.style.FullScreenDialogWithStatusBarColorAccent)
}
Add this style in style.xml
<style name="FullScreenDialogWithStatusBarColorAccent">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="android:statusBarColor">#color/colorAccent</item>
<!--<item name="android:windowAnimationStyle">#style/MateriDocumentAlertsActivityalDialogSheetAnimation</item>-->
</style>
here is the solution i found:
add this to your style.xml file
<style name="BottomSheetDialogTheme" parent="BaseBottomSheetDialog">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<!-- set the rounded drawable as background to your bottom sheet -->
<style name="BottomSheet" parent="#style/Widget.Design.BottomSheet.Modal">
<item name="android:background">#color/transparent</item>
</style>
<style name="BaseBottomSheetDialog" parent="#style/Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="bottomSheetStyle">#style/BottomSheet</item>
</style>
then you should override onCreate() method in BottomSheetDialogFragment class and call:
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.BottomSheetDialogTheme);
}
in kotlin
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window?.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window?.statusBarColor = Color.parseColor("#0173B7")
}
A little late to the party but setting IS_FLOATING flag worked for me.
<style name="MyTheme.AlertDialog.FullScreen" parent="MyTheme.AlertDialog">
<item name="windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">#style/Animation.AppCompat.Dialog</item>
<item name="android:windowBackground">#color/white</item>
</style>
I used app compat theme style .
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:itemTextAppearance">#style/myCustomMenuTextApearance</item>
<item name="android:listPopupWindowStyle">#style/PopupMenuStyle</item>
</style>
<style name="PopupMenuStyle" parent="Widget.AppCompat.ListPopupWindow">
<item name="android:divider">#drawable/devider</item>
<item name="android:dividerHeight">2dp</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#color/search_panel_color</item>
<item name="android:textColor">#color/activity_button_text_color</item>
<item name="android:shadowColor">#color/activity_theam_color</item>
</style>
<style name="myCustomMenuTextApearance" parent="#android:style/TextAppearance.Widget.TextView.PopupMenu">
<item name="android:textColor">#color/activity_theam_color</item>
</style>
I want to add a divider in my menu item.
I've tried so many things, but the divider is not applying...
Is there any way to show the divider?
I also have the same problem. The solution is like this:
<style name="PopupMenuListView" parent="#style/Widget.AppCompat.ListView.DropDown">
<item name="android:divider">#000000</item>
<item name="android:dividerHeight">1dp</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:dropDownListViewStyle">#style/PopupMenuListView</item>
</style>
You can also refer to the following link:
How to add dividers between specific menu items?
I have one solution.you can design popup as per your choice by programming.use below code to display popup menu.
private ListPopupWindow listPopupWindow;
listPopupWindow = new ListPopupWindow(getApplicationContext());
listPopupWindow.setWidth(400);
listPopupWindow.setDropDownGravity(Gravity.CENTER);
listPopupWindow.setAdapter(new listpopupadapter(a, type));
listPopupWindow.setAnchorView(v);
listPopupWindow.show();
Here listpopupadapter is class to design your list as it below.
public class listpopupadapter extends BaseAdapter {
ArrayList<String> a;
String type;
public listpopupadapter(ArrayList<String> a, String type) {
this.a = a;
this.type = type;
}
#Override
public int getCount() {
return a.size();
}
#Override
public Object getItem(int position) {
return getItem(position);
}
#Override
public long getItemId(int position) {
return position;
}
#SuppressLint("ViewHolder")
#Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
View root = LayoutInflater.from(parent.getContext()).inflate(
R.layout.raw_filter, null);
}
}
From your theme style, I guessed you used Toolbar. Is your menu popup is showed from Toolbar? If so, you can customize as the following step.
Define the theme
<style name="AppToolbarPopupTheme" parent="Widget.AppCompat.PopupMenu.Overflow">
<item name="android:dropDownListViewStyle">#style/AppDropDownListViewStyle</item>
</style>
<style name="AppDropDownListViewStyle" parent="Widget.AppCompat.ListView.DropDown">
<item name="android:divider">#drawable/line_divider</item>
<item name="android:dividerHeight">1dp</item>
</style>
Then apply the theme to Toolbar
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:popupTheme="#style/AppToolbarPopupTheme">
</android.support.v7.widget.Toolbar>
if you haven't found the answer to this question then this is how it worked for me using the style:
<style name="PopupMenu">
<item name="android:itemBackground">#color/background_medium_gray</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:colorBackground">#color/BackgroundGray</item>
<item name="android:dividerHeight">1dp</item>
</style>
Context context = new ContextThemeWrapper(getActivity(), R.style.PopupMenu);
final PopupMenu popupMenu = new PopupMenu(context, view);
final MenuInflater menuInflater = popupMenu.getMenuInflater();
I suggest you add dummy groups,try this way
<group>
<!--add it like as a separator-->
<item
android:title=""
android:showAsAction="always"
android:enabled="false" />
</group>
Using a Material theme removes dividers.May be this is the simple solution to this problem.
You can try this or any holo theme (i.e #android:style/Widget.ListPopupWindow) to get divider effect in popup
<!-- Change Overflow Menu ListView Divider Property -->
<style name="PopupMenuListView" parent="android:Widget.ListPopupWindow">
<item name="android:divider">#FF0000</item>
<item name="android:dividerHeight">2dp</item>
</style>
I've made a driver app that needed a popup the ride was coming, at that time I used this one. So please try this one. Maybe it will help.
<activity
android:name="driver_activity_name
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
I'm trying to customize casting controller dialog and I have problems changing dialog's title style. I've implemented it like CCL library does but without success.
This is my relevant code:
VideoMediaRouteControllerDialog.java
public VideoMediaRouteControllerDialog(Context context) {
super(context, xxx.xxx.R.style.TTNCastDialog);
...
}
VideoMediaRouteControllerDialogFragment.java
public class VideoMediaRouteControllerDialogFragment extends MediaRouteControllerDialogFragment {
#Override
public VideoMediaRouteControllerDialog onCreateControllerDialog(Context context, Bundle savedInstanceState) {
VideoMediaRouteControllerDialog customControllerDialog = new VideoMediaRouteControllerDialog(context);
customControllerDialog.setVolumeControlEnabled(false);
return customControllerDialog;
}
}
VideoMediaRouteDialogFactory.java
public class VideoMediaRouteDialogFactory extends MediaRouteDialogFactory {
#Override
public VideoMediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
return new VideoMediaRouteControllerDialogFragment();
}
}
styles.xml
<style name="TTNCastDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/TTNCastDialogWindowTitle</item>
</style>
<style name="TTNCastDialogWindowTitle">
<item name="android:textSize">22sp</item>
<item name="android:textColor">#color/ccl_mr_custom_title</item>
</style>
styles.xml(v21)
<style name="TTNCastDialog" parent="android:Theme.Material.Dialog">
<item name="android:windowTitleStyle">#style/TTNCastDialogWindowTitle</item>
</style>
I've taken a look at MediaRouteThemeHelper's getButtonTextColor method
and it returns accent color instead of primary color. My application theme extends of Theme.AppCompat.Light.NoActionBar
I've tried this way too
styles.xml
<style name="TTNCastDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowTitleStyle">#style/TTNCastDialogWindowTitle</item>
</style>
<style name="TTNCastDialogWindowTitle">
<item name="android:textSize">22sp</item>
<item name="android:textColor">#color/ccl_mr_custom_title</item>
</style>
But it did not work.
Any suggestions?
Thanks
Background
I have an activity in my app that has a toolbar as the actionBar, and it also has an actionMode, for multi-selection of items.
The problem
Every time I close the actionMode, there is a "jump" between the two modes, so I can see both the toolbar and the actionMode.
Maybe I'm just doing it wrong, but I remember it worked fine in the past.
Here's how it looks like using the snippet code I've made:
What I've tried
This is a snippet of the code I've used. To test it, run the app, wait a moment for the actionMode to appear, and then either press the back button, or press the button on the actionMode. Do note that all classes that I use are of the support library (when available).
MainActivity.java
public class MainActivity extends AppCompatActivity {
protected ActionMode.Callback _actionModeCallback;
protected ActionMode _actionMode;
Toolbar _toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_toolbar = (Toolbar) findViewById(R.id.activity_app_list__toolbar);
setSupportActionBar(_toolbar);
_actionModeCallback = new ActionMode.Callback() {
#Override
public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
return false;
}
#Override
public void onDestroyActionMode(final ActionMode mode) {
_toolbar.setVisibility(View.VISIBLE);
_actionMode = null;
}
#Override
public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
_toolbar.setVisibility(View.GONE);
return true;
}
#Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
mode.finish();
return true;
}
};
//
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
_actionMode = startSupportActionMode(_actionModeCallback);
}
}, 2000);
}
}
activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/activity_app_list__toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:colorControlNormal="?attr/colorControlNormal"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
tools:ignore="UnusedAttribute"/>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"/>
</FrameLayout>
</LinearLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
<item name="colorPrimary">#FF0288D1</item>
</style>
</resources>
The question
Why is this happenning? How can I fix it?
Is this a known bug, perhaps?
What you're looking for is the ACTION_MODE_OVERLAY flag. In your Activity.onCreate() method, add the following before the call to super.onCreate():
#Override
protected void onCreate(Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
super.onCreate(savedInstanceState);
// other stuff...
}
The same as described by #Kevin Coppock can also be achieved by adding <item name="windowActionModeOverlay">true</item> in your AppTheme.
The theme could look like this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
<item name="colorPrimary">#FF0288D1</item>
<item name="windowActionModeOverlay">true</item>
</style>
I have a DialogFragment which I want to show in fullscreen. I do however still want a StatusBar present, and the hardware buttons at the bottom. I also want to set a background color of the StatusBar (for Lollipop).
My problem is that if I set the following flags in the DialogFragment:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Both the StatusBar and Hardware keyboard becomes translucent, and the DialogFragment stretches behind these.
Here is the code, which has been greatly reduced to become readable:
public class CardDetailsDialog extends DialogFragment {
Setup parameters...
public static CardDetailsDialog newInstance(final long cardId, final long projectId){
CardDetailsDialog frag = new CardDetailsDialog();
frag.setStyle(DialogFragment.STYLE_NORMAL, R.style.CardDetailsDialogStyle);
return frag;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if(getDialog() != null) {
getDialog().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogSlideAnimation;
getDialog().getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
getDialog().getWindow().setStatusBarColor(Color.RED);
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.card_details, container, false);
Handle everything that happens inside the view...
return view;
}
}
Here is the referred theme:
<style name="CardDetailsDialogStyle" parent="#style/Theme.AppCompat.Light.Dialog" >
<item name="android:windowBackground">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
And the style of the fragment:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/pp.whiteBackgroundColor" >
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_details_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/PopupMenutheme">
</android.support.v7.widget.Toolbar>
<ScrollView
android:id="#+id/details_scrollview"
android:layout_height="wrap_content"
android:layout_width="match_parent">
All subview elements here...
</ScrollView>
</RelativeLayout>
This is the result:
As you can see, the ToolBar extends over the StatusBar and hardware buttons. I don't know if I am approaching this correctly. Am I missing something?
EDIT
This is what the same view look likes when I remove
getDialog().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
For anyone who's still having this problem, do the following. This just solves half of the problem that is posted i.e. black status bar.
Add following theme to res/value-v21/style
<style name="DialogTheme" parent="#style/Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowTranslucentStatus">true</item>
</style>
And then apply Style on DialogFragment in onCreate
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.DialogTheme);
}
Edit
if you've problem with your dialog theme then use this style e.g. colorAccent or colorControlHighlight etc
<style name="DialogTheme" parent="#style/ThemeOverlay.AppCompat.Dialog">
<item name="android:windowTranslucentStatus">true</item>
</style>
In my case SYSTEM_UI_FLAG_LAYOUT_STABLE solved problem with overlapping
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width,height);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
dialog.getWindow().setStatusBarColor(getResources().getColor(R.color.darkGrayTransp));
dialog.getWindow().getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_STABLE);//solves issue with statusbar
dialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL| Gravity.TOP);
}
Try use the same Style from your App. I tested with simple dialog without fragment and works fine.
Like that:
new Dialog(context, R.style.CardDetailsDialogStyle);
You have to set fitsystemwindows = true. Other way is to add a Space with 0dp and change its height to 25dp when the dialog is going to show.
To change the space size, use layout params, check this post: How to create a RelativeLayout programmatically with two buttons one on top of the other?
<style name="DialogTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
</style>
Just apply android:fitsSystemWindows="true" to your root ViewGroup:
`<FrameLayout
android:fitsSystemWindows="true">
<View .../>