How to create a dialog style that looks as snackbar style - android

I am trying to write a custom dialog style that will give me the styling of a snackbar where the dialog is anchored at the bottom of the screen where there is no gap between the box and the navigation control and takes up full width of the screen.
sample_look
How do i style this?
<style name="AlertDialogCustom" parent="#android:style/Theme.Dialog">
</style>

If you want dialog to appear at bottom , then you can set the gravity appropriately .
Window window = getDialog().getWindow();
window.setGravity(Gravity.BOTTOM);
You can also use bottomsheet dialog .

Related

Android bottom sheet dialog how to set scrim animation

I noticed that by default, when a bottom sheet dialog is shown, the scrim just pop up without any animation, which is not a good user experience. So I was wondering how to show the scrim with animation. Any suggestion?
You can use
getDialog().getWindow().getAttributes().windowAnimations = *Your animation here*(
For example, R.style.myAnimation
<style name="myAnimation">
<item name="android:windowEnterAnimation">#anim/up</item>
<item name="android:windowExitAnimation">#anim/down</item>
</style>
)

DialogFragment change shadow(mask) color (NOT dialog content)

I am building a dialog with DialogFragment, and I need to change the color of the shadow (mask), which is transparent and always around the main dialog content. Actually, almost all of the answers on the web is to change the dialog box color, but I need to change the shadow color from transparent black to others. Is there any way to do that?
image:
If you only want to change the alpha for the background then you can easily create a style with android:backgroundDimAmount attribute, like I did
<style name="CustomAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:backgroundDimAmount">0.5</item>
</style>
the value ranges 0-1 and then passing the style in your AlertDialog as
AlertDialog dialog = new AlertDialog.Builder(this, R.style.CustomAlertDialogStyle)
.setTitle("Title").setMessage("message").create();
dialog.show();
But if you want to change the background color as well then you can try this work around given by #Lee Han Kyeol
https://stackoverflow.com/a/29482234/5002610
I hope this will solve your issue.

Change dialog text color on 5.0+

I'm trying to change the text color in dialog boxes, most commonly AlertDialog. I've tried every solution at these pages:
AlertDialog styling - how to change style (color) of title, message, etc
How can I change the color of AlertDialog title and the color of the line under it
How to change theme for AlertDialog
Most solutions work BELOW 5.0 but above it, and they don't seem to have any effect. What different attributes should I be changing for 5.0+?
The parent theme of my app is "Theme.AppCompat.Light.NoActionBar"
In your case, I think the dialog theme would work.
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.YourDialogStyle;
You can specify your dialog theme just like the code above.
<style name="YourDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:colorAccent">#color/primary</item>
<item name="android:textColor">#color/accent</item>
<item name="android:textColorPrimary">#color/primary_dark</item>
</style>
Here is the example of theme for Dialog.
android:colorAccent will affect your text colors of negative or positive buttons.
android:textColor will affect your title text color of dialog.
android:textColorPrimary will affect your message color of dialog.
Another option is you can make your own custom layout for the dialog.

Changing Background dim color for dialog appears in android

Hi I have to chage the dim color of dialog in my theme to white, so that by setting layoutParams.dimAmount = 0.5f; i can get blur white in dialog background.
I am using
<style name="MyDialog" parent="#android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">#color/dialog_dim_background</item>
</style>
and following below references
How do I create a transparent Activity on Android?
Custom screen dim with Dialog
It is a very old question, but i'd like to add n answer to it. I faced the same problem and googled a lot. Then came up with my own solution.
First of all, I removed the dim at all with this
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
And then I opened my layout(it was RelativeLayout) and put this view in it as the last element
<View
android:id="#+id/shade"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primaryShadow"
android:visibility="invisible"/>
The background color is the color you want to use as your dim color. As you can see, it is invisible when created. So you'll need to find it in you Activity and set it's visibility before you launch the dialog to View.VISIBLE. When you cancel dialog, set it to View.INVISIBLE again. And that's it.
I know it's very old question but this will help out surely to someone who is using AppCompatActivity or ActionBarActivity. If you are setting a dialog to your activity or say DialogActivity then also the below will work!
dialog = new Dialog(ActivityName.this);
dialog .setCancelable(false);
dialog .setContentView(R.layout.dialog_layout);
Window window = dialog.getWindow();
if(window != null){
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setDimAmount(0.5f);
//If you are setting a dialog activity
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
Double dialogWidth = displayMetrics.widthPixels * 0.50;
window.setLayout(dialogWidth.intValue(),
WindowManager.LayoutParams.WRAP_CONTENT); //Setting it cover half of the screen width
}
dialog.show();
Just before you dismiss the dialog,
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.dismiss();
//If you are setting a dialog activity, create a style in styles.xml:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
And in your Manifest, set the theme:
<activity android:name=".view.POSSelectCustomerDialogActivity"
android:theme="#style/MyTheme"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"/>
Ok here is how I do that "I don't know how will these behave with the blur flag though"
I create a custom layout for the dialog with a background color of my choosing .
set the dialog to fill screen
remove the dim behind flag
Code snippet
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dailog_layout);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(0));
dialog.getWindow().setLayout(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
dialog.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Best of luck

How to create a completely custom Dialogue/Popup in Android (change overlay colour and dialogue window layout)

I would like to completely re-skin the default dialogue component in Android. Specifically I would like to do this:
Change the semi-transparent overlay background from the default black to a semi-transparent white.
Change the Dialogue window by
removing the default windowed frame border,
and replacing it with a layout
defined in XML (it's just going to be
a borderless graphic with floating
buttons. no actual frame.)
I have seen tutorials about creating a custom layout for within the dialogue box (e.g. http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application), but I haven't seen anything regarding changing the colour of the overlay and/or completely customizing the dialogue window that pops up and turning it more into an overlay with no "window".
I've solved this problem and created my own custom popup overlay with a custom coloured semi-transparent overlay background using the following steps:
1 - Create a new xml file in your res/values/ folder and name it styles.xml
2 - Here is where you will define your dialog properties. Here is what mine looks like. If you want to replace the default semi-transparent black overlay that shows over the screen, you have to set windowIsFloating to false, and modify the background of your layout to be whatever colour you want. Here is my file below that I've used:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#color/transparent_white</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
3 - Back in your java code, when creating the dialog object, use the constructor that passes both the context AND the theme. Eg. myDialog = new Dialog(this, R.style.CustomDialogTheme); (CustomDialogTheme is the name attribute I specified in the styles.xml from step 2)
4 - Simply set your dialog objects content view to whatever layout you want your dialog to look like. Eg. myDialog.setContentView(R.layout.my_custom_overlay);
If you want your dialog to appear at the center of the screen, set its root element's android:layout_gravity to center
This worked great for me, but is missing how to close the dialog. if you have a button in your custom layout to close it, here is how to add the listener and close the dialog window.
final Dialog d = new Dialog(this,R.style.CustomDialogTheme);
d.setContentView(R.layout.custom_dialog);
d.show();
Button close_btn = (Button) d.findViewById(R.id.close_btn);
close_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
d.dismiss();
}
});

Categories

Resources