I want to use a custom color for the Dialog in ICS-Devices. The default one is blue (see image), how can I set this to a color that fits my app color scheme, e.g. red ?
Try this:
alert.setTitle(Html.fromHtml("<font color='#FF0000'>User Agent</font>"));
You can try this:
AlertDialog alert = builder.create();
alert.show();
alert.getListView().setBackgroundColor(Color.RED); //This is for Color
alert.setCancelable(true);
Related
I have a AlertDialog with a custom view that contains two EditText fields. At some point the dialog is show using the following code:
val builder = AlertDialog.Builder(this)
builder
.setView(R.layout.dialog)
.setMessage("message")
.setPositiveButton("Oke"){ dialog, id -> println("oke")}
.setNegativeButton("Cancel"){ dialog, id -> println("cancel")}
val dialog = builder.create()
dialog.show()
When the user pressed a EditText the SoftKeyboard show up but the Dialog is not being shifted up. I have tried settings the softinputmode of the dialog.window to SOFT_INPUT_ADJUST_PAN or SOFT_INPUT_ADJUST_RESIZE like this.
dialog.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
but this doesn't seem to do anything.
The Activity in which the AlertDialog is shown had a translucent status bar theme.
So instead of initializing the builder with the classic AlertDialog.Builder(this) which uses the context's theme, you can use a dialog theme with no translucent status bar to it:
val builder = AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar)
This theme ensures compatibility with pre-lollipop devices too, but other ones like android.R.style.Theme_Material_Dialog should do the trick too.
Try this:
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
In my activity theme in the themes.xml I have set a background color in order to move away from the default (transparent/white?) background color to my own.
<item name="android:background">#color/red</item>
Unfortunately, when the I am showing my loading dialog the color shines halfway through that dialog now. Was this to be expected?
I have tried to use different themes, also defined by own dialog theme subclassing from Holo Light setting the background color explicitly to white, but the problem persists, only the currently still white areas are changed in this case.
What can I do? The only alternative is currently to use the Tradiotional Dialog Theme.
Try to set android:windowBackground instead. android:background attribute is applied to all nested views. Here is the discussion: What's the difference between windowBackground and background for activities style?
It looks like there's some padding or margins to the left and right of the title. If you're using the built-in ProgressDialog I'd suggest creating your own Dialog instead, that way you can change anything you want about it. Just create your own xml layout and create the dialog like this:
protected static Dialog getProgressDialog(Activity activity) {
Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View progressDialogView = inflater.inflate(R.layout.custom_progress_dialog, null);
dialog.setContentView(progressDialogView);
dialog.setCancelable(false);
return dialog;
}
I have a dialog that comes up in my app and I wanted to stray away from using the default dialog, to give something slightly more customized. In my dialog layout, I included the following:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/My_Custom_Background">
This does basically what I want it to, it changes the background as expected. However, this only applies to the layout of the contents of the dialog box: the dialog also has a title and the title part of the dialog box is still the default Android theme, then everything under it is customized as I wanted. Is there away to extend the custom background to the entire dialog box?
You need to remove the title bar
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog);
Make sure to call requestWindowFeature() before the setContentView() otherwise you get a FATAL EXCEPTION
you can create your dialog as below
Dialog mDialog = new Dialog(mContext);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
mDialog.setContentView(R.layout.your_custom_dialog_layout);
mDialog.setCancelable(false);
mDialog.show();
and inside your custom layout, you can set the custom drawable as a background.
An alternate is to remove your dialog titlebar using this...
yourdialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
and design whole dialog with title inside your layout...
I am working on an android application that allows user to add an edit text dynamically. I have been able to add the edit text using an alert dialog. But I need to make the dialog box transparent .I need to be able to see the imageview in the background. Color.Transparent wont work because my background is an image
Try this:
Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
or
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
You can try this
<EditText
android:id="#+id/purpose_textfield"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#null"/>
Instead of Using alert Dialog Box, i prefer you to use Dialog box:
And use this code:
Dialog dialog = new Dialog(getBaseContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
Hi Friends
how to change alertDilog Box Design by Style or Theme?
Transparent AlertDialog : Set Transparent Window in AlertDialog box
You can look at Tutorial here :
http://androidgenuine.com/?tag=custom-alertdialog