Size of Alert Dialog or Custom Alert Dialog - android

I am creating my application for all tablets of 10.1 and now i am trying this on samsung galaxy tab.
I have done all the parts of that but alert dialog is too small regarding tablet size.
I have also created custom alert dialog but it does not look good.
So tell me can i change the size of default alert dialog if yes then how.
OR
how to create custom alert dialog that looks like default alert dialog.
Thanks.

Please Refer this one
According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window's top level layout width and height to WRAP_CONTENT. To make the Dialog bigger, you can set those parameters to FILL_PARENT.
Demo code:
AlertDialog.Builder adb = new AlertDialog.Builder(this);
Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
d.show();
d.getWindow().setAttributes(lp);
Note that the attributes are set after the Dialog is shown. The system is finicky about when they are set. (I guess that the layout engine must set them the first time the dialog is shown, or something.)
It would be better to do this by extending Theme.Dialog, then you wouldn't have to play a guessing game about when to call setAttributes. (Although it's a bit more work to have the dialog automatically adopt an appropriate light or dark theme, or the Honeycomb Holo theme. That can be done according to http://developer.android.com/guide/topics/ui/themes.html#SelectATheme )

Related

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...

Weird black line above DialogFragment AlertDialog

I have a screenshot below of a random dark/black slightly downwards gradient line appearing above my dialog fragments.
These are build with a dialogfragment class that has been overridden, and an alertdialog builder is being used to construct them (happens with and without the title/buttons) inside the following method
public Dialog onCreateDialog(Bundle savedInstanceState)
Anyone had this happen to them before or have any ideas?
Ive tried to theme them differently, and the same happens with both API14 holo and holoeverywhere library. Ive tried to set the backgrounds to transparent ect... but havent achieved anything except making the dim go away.
You need to add your custom theme for your dialog and provide android:windowContentOverlay parameter.
<style name="MyDialogTheme">
<item name="android:windowContentOverlay">#null</item>
</style>
Then, in your DialogFragment in onCreate call:
setStyle(/* desired style */, R.style.MyDialogTheme);
The Weird Line appears because of the title bar. You just need to hide the title bar and it automatically hides the weird line:
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
// request a window without the title
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
// make your dialog here
return dialog;
}
Try this,
private Dialog custom_dialog;
private Window window;
custom_dialog = new Dialog(context);
custom_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
custom_dialog.setContentView(R.layout.share_dialog);
custom_dialog.setCancelable(true);
//Below code is used to remove wired black line
window = custom_dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
window.setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
window.setBackgroundDrawableResource(R.drawable.empty);
Found one way of getting around my problem.
So the deal was that the FrameLayout (with id: android:id/content) that the system makes itself had a foreground drawable on it (the shadow at the top of the frame). I couldnt for the life of me deal with it with styles or anything, nor could i figure out why it was happening on these two custom alert dialogs inside dialogfragments.
note: im using a HoloEverywhere fork thats compatible with v7 AppCompat, but keeping as many of the classes ect... from the actual support libraries.
I could however access the framelayout and remove the foreground drawable with this:
(note: it had to be in the onresume as i dont think there are any calls before that resulted in a "android.util.AndroidRuntimeException: requestFeature() must be called before adding content" error.
public void onResume() {
super.onResume();
((FrameLayout) getDialog().getWindow().getDecorView().findViewById(android.R.id.content)).setForeground(new ColorDrawable(android.graphics.Color.TRANSPARENT));
}
If theres a better safer way of doing this, or if anyone knows why this is happening, let me know.

Dim or Blur background in activity

In one of my project I used PopupWindow. My problem is while viewing popupwindow the design seems to be uncomfortable to work. So I want to dim or blur my activity background. I searched a lot, but most of the answers seems only for Dialog not for PopupWindow. Is it possible in android to dim our activity background while viewing PopupWindaow.
I solved this problem by setting the background to the layout of the pop-up window with the following.
android:background="#80FFFFFF"
Thnaks..And it works as expected.
you can simply use this :
ColorDrawable dw = new ColorDrawable(0xb0000000);
dialog.getWindow().setBackgroundDrawable(dw);
There is always a work around. Before showing your PopupWindow use another PopupWindow which has nothing but a dark translucent tint. Also when dismissing dismiss both pop up windows in the reverse sequence.
For code see this
Yes, it is possible, try android:theme="#android:style/Theme.Translucent" , it will make your activity transparent.
Try this
Window window = popUpView.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.CENTER_VERTICAL;
wlp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
wlp.dimAmount = (float) 1.0;
window.setAttributes(wlp);

How can I display a dialog above the keyboard

I'm a newbie with android, I write an application which using the Dialog to display data when user select on one thing. This is how the dialog looks:
https://docs.google.com/file/d/0B3NUAgD0tB0YOS16azFCWXdSVVE/edit
But when I tap on the last EditText to enter some data, the dialog still shows, when I type the first character, the dialog scrolls down. The dialog stays behind the keyboard, with some parts totally obscured.
Could anyone tell me how to show the whole dialog above the soft keyboard? This is how I'd like it to look:
https://docs.google.com/file/d/0B3NUAgD0tB0YOFVQYUF0U0JvOEk/edit
Thanks
Clark
Have you tried ths one?
Worked for me:
http://developer.android.com/reference/android/view/Window.html#setSoftInputMode(int).
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
You may need to set dialog's width and height manually in order to make soft input mode work like this:
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
params.gravity = Gravity.CENTER;
window.setAttributes(params);
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
create a Xml file name style.xml
<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowSoftInputMode">stateUnchanged</item>
<item name="android:windowBackground">#color/dialog_transparent</item>
</style>
then Implement
this works for me hoping it will work for you also.
final Dialog dialog = new Dialog(this , R.style.FullHeightDialog);
and also do changes in your manifest file
android:windowSoftInputMode="adjustResize|adjustPan"
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.show();
Window window = dialog.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

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.

Categories

Resources