Setting the backgroung of a Dialog box as transparent - android

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);

Related

Android alertdialog not centered when keyboard opens

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);

Change the font of Custom dialog box title

Here's my code for the custom dialog box I've implemented
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("This is the Title");
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setTypeface(Typeface.createFromAsset(getAssets(),
"fonts/Barkentina.otf"));
I'm easily able to change the font of the text inside dialogue box. But what can I do to change the font of dialog title?
If you want to override the font in your entire application then you can follow this answer.
As per your approach you can follow this answer which uses R.id.alertTitle to find the alter dialog title id. Then you can set typeface to the TextView with the id.

Setting background to a 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...

AlertDialog is not rendering correctly

As you can see in the screenshot, my alert dialog border is not rendering correctly. It is placing a black background behind the dialog. This only happens when I resize the dialog. I'm new to android/monodroid so I don't really even know where to start looking for a cure. You can see that the toast message renders the border properly (with a semi-transparent border).
Any thoughts on how I can get rid of the black background behind the dialog border ?
resizing code:
Dialog dialog = db.Create();
WindowManagerLayoutParams p = new WindowManagerLayoutParams();
p.CopyFrom(dialog.Window.Attributes);
p.Width = 900;
p.Height = WindowManagerLayoutParams.WrapContent;
dialog.Show();
dialog.Window.Attributes = p;
I would advice to use the DialogFragment instead of the older dialog, at work we have had quite a few problems with the older dialogs.
http://developer.android.com/reference/android/app/DialogFragment.html
And this problem in specific on a few devices.

Android ICS Dialog Title Color

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);

Categories

Resources