Dialog theme animation issue - android

I have create a dialog using AlertDialog class. With custom view. I want to set entry and exit animation for it. when I try to do that dialog converts itself to small black background view. How to get animation with proper view ??
final AlertDialog.Builder builder = new AlertDialog.Builder(
/*getContext()*/
new android.support.v7.view.ContextThemeWrapper(getContext(), R.style.StyleDialog));
View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_email, null);
builder.setView(view);
builder.setCancelable(false);
alert = builder.create();
alert.show();
These are the styles
<style name="StyleDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowAnimationStyle">#style/DialogAnimation</item>
</style>
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">#anim/fadein</item>
<item name="android:windowExitAnimation">#anim/fadeout</item>
</style>
tried both android.support.v7.view.ContextThemeWrapper and android.view.ContextThemeWrapper but no difference.
Using android.app.AlertDialog class.

I found the solution. Just set background(in my case white) for layout which I had not given. Because when we set our own style then it use black background by default and if do not set style then it uses white background by default.
android:background="#color/bg_white"
For proper width, set first view width to match_parent.
android:layout_width="match_parent"

Related

Android support alert dialog change header background color?

color/colorPrimary is some orange color I want header has it. But I succeded to change header text color which is easy . I would like to change color of header background. This is what I have so far:
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#color/colorPrimary</item>
<item name="android:windowTitleBackgroundStyle">#style/dialog_title_style</item>
<item name="android:alertDialogStyle">#style/AlertDialog_Sphinx</item>
<item name="colorAccent">#color/colorPrimary</item>
</style>
<style name="dialog_title_style" >
<item name="android:background">#color/colorPrimary</item>
<item name="android:padding">100dp</item>
</style>
<style name="AlertDialog_Sphinx">
<item name="android:fullDark">#color/colorPrimary</item>
<item name="android:topDark">#color/colorPrimary</item>
<item name="android:centerDark">#color/colorPrimary</item>
<item name="android:bottomDark">#color/colorPrimary</item>
<item name="android:fullBright">#color/colorPrimary</item>
<item name="android:topBright">#color/colorPrimary</item>
<item name="android:centerBright">#color/colorPrimary</item>
<item name="android:bottomBright">#color/colorPrimary</item>
<item name="android:bottomMedium">#color/colorPrimary</item>
<item name="android:centerMedium">#color/colorPrimary</item>
</style>
public class MyDialogFragment extends DialogFragment {
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle).setTitle("Naslov")
.setMessage("Poruka......................................................")
.setIcon(android.R.drawable.ic_menu_help)
.setPositiveButton("OK",null);
return builder.create();
}
}
I'm using support version of AlertDialog.(23.1.0) This way dialog look more like dialog on newer version of android(Material Design)
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
I want that header is of color/colorPrimary (orange) background.
In the latest API levels the alert dialog does not have a separate header. It has a single view and a divider which separates the header text and message. You can change the header text and message text colors and also the divider colour. Also, you can change the background of the entire alert dialog but not just the header section of it.
As a workaround what you can do is: Dont set header text but use an image with text in it followed by the message. This way the divider will vanish and the image will look like the header.
Basically a custom alert dialog.
Check this post to see how to add an image in alertdialogs.
You can create a custom view for the alert dialog.
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) getCurrentFocus());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);
builder.show();
You can check out this material dialogs library here. It is very easy to use and also very customizable.

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 remove white border on my custom dialog in my case

I created my custom dialog:
//generate dialog view
LayoutInflater layoutInflater = LayoutInflater.from(activity);
View dialogView = layoutInflater.inflate(R.layout.warning_dialog, null);
//create dialog instance
Dialog warningDlg = new Dialog(getActivity(), R.style.CustomAlertDialog); //my dialog style
warningDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
warningDlg.setContentView(dialogView);
warningDlg.show();
As you see above, when I create my dialog instance, I use my own style named "CustomAlertDialog", which is like following:
<style name="CustomAlertDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#drawable/my_dialog_bg</item>
</style>
Things are working well except that I got white border on my dialog window when showing on Android 2.3.3 device, how can I remove the white border with my above codes?

XML attributes for text color of alert dialog

I'm applying a theme:
<style name="myAlertTheme" parent="#android:style/AlertDialog">
<item name="android:textColor">#ff000000</item>
</style>
<style name="RadioButton" parent="#android:style/Widget.CompoundButton.RadioButton">
<item name="android:textColor">#ff000000</item>
</style>
<style name="HSDroidStyle" parent="android:Theme">
<item name="android:background">#ffd3d3d3</item>
<item name="android:textColor">#ff000000</item>
<item name="android:textSize">20dp</item>
<item name="android:radioButtonStyle">#style/RadioButton</item>
</style>
But when I create an Alert, the text shows up as white instead of black. To create the alert I'm using:
AlertDialog alertDialog = new AlertDialog.Builder(
new ContextThemeWrapper(act, R.style.myAlertTheme)).create();
alertDialog.setTitle(title);
alertDialog.setMessage(msg);
alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (exitOnFailure) mainAct.finish();
return;
} });
alertDialog.show();
Now the "OK" in the button changes if I change the size in the myAlertTheme, but not the title or the text. So I'm guessing that there is some other textColor attribute that addresses this. I've tried most of the ones I can think of, but none of them work.
Any ideas?
hooked82 is right. Prior to Honeycomb, Android did not support text styling properly for AlertDialogs. You could apply styles to an AlertDialog, but it would ignore the text styles.
Here's a good SO answer that would prove to be a good solution for you: How to change theme for AlertDialog
Here's a really useful blog post that uses the propsed solution above to style an AlertDialog properly.
AFAIK there isn't a way to modify the Title/Message text colors (Please correct me if I'm wrong). So one way of doing this would be to create a custom view for your AlertDialog and do something like the following:
LayoutInflater factory = LayoutInflater.from(this);
final View layout = factory.inflate(R.layout.alert_layout, null);
alertDialog.setView(layout);
Try to declare the AlertDialog using this statement:
AlertDialog alertDialog = new AlertDialog(mContext, R.style.myAlertTheme);

Categories

Resources