Is it possible to have an Android Alert box or Dialog off-center? I have tried everything that comes to mind, including making a custom Dialog activity and theme (extending Android:Theme.Dialog), but I have not been able to move it from it's centered position.
Yes you can make the background translucent and fill the entire view, then nest a visible layout within that you can use layout_gravity="top|left" on.
A little off topic, but if you just want to display text, an easier way is to use a toast.
Toast toast = new Toast(new ContextThemeWrapper(getApplicationContext(), R.style.YourDialogStyle));
toast.setGravity(Gravity.LEFT|Gravity.TOP, 0,0);
PopupWindow? An example can be found here: http://www.anddev.org/how_to_create_a_popupwindow-t1259.html
Related
I have a list of options that are shown in an AlertDialog. The AlertDialog populates the list from a SharedPreferences file. Currently the user makes a selection, the AlertDialog closes and depending on the choice some edit text fields are filled in.
I would like to add an OnLongClickListener call to each option in the list, which when utilized would pop up another AlertDialog, over the top of the existing one, with a simple "are you sure you want to delete this?" question, then a yes and no button.
The dialog creation is simple, I just want to know if the OnLongClickListener can be applied and if AlertDialogs can be down on top of each other?
my answer here may help with adding an OnLongClickListener. The code I added is at the bottom of my response.
You can accomplish what you want by setting a new OnShowListener on your dialog and overriding the onShow() method
I want to collect user input from a dialog box caller alert1.
AlertDialog.Builder alert1=new AlertDialog.Builder(context);
LinearLayout layout1=new LinearLayout(context);//context is an object of type Context previously initialised to 'this'
layout1.addView(box1);//box1 is an EditText
alert1.setView(layout1);
alert1.show();
this however makes the edittext appear reallys small. but if i do this instead
alert1.setView(box1);
and get rid of the LinearLayout all together it appears right but i cant add anymore custom ui controls to this alert box. Can someone tell me where i'm wrong
its for target android 4.0
also i tried both orientations for the linear layout..
Try to set LayoutParams in the LinearLayout with the following code linearLayout.setLayoutParams(params);.
Hi I want to make a custom dialogue box for my android application and want to populate it with buttons, check boxes and such kind of items.
I have followed the tutorial from android developers website, but that is not what I want, actually I want to customise the background and size of the dialogue box.
Please if any body could give me a head start, Plus I want to know when I design a background for that box, what dimensions and pixel numbers I use so that it may run the same in Galaxy Note, Galaxy S and tablets and other mobile phones running android.
Here is the picture of customised dialogue box. Like that I want to work out something.
Yes this is a good question. You must use a custom dialog with a transparent bg theme like these:
Dialog dialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog);
dialog.show();
where custom_dialog will be your XML for the dialog layout, and as far as dimensions go you should really test your app on a number of different screen resolution devices to ensure it displays as you want.
On occasion I have wanted to create a fully customized dialog such as the one you've shown.
When I had to do it, I fought for a while trying to make it a Dialog. In the end I found it was far easier to just wrap my dialog in its own activity, set it to theme transparent in the manifest, and make the layout xml file such that there was transparent space around the edges. That was the easiest way for me to get rid of all of the default dialog formatting (i.e. the frame that it comes in if you do it with the setContentView() route)
So while it is not technically a dialog any more, to the user it serves the same purpose.
I have a standard (not custom, no layout) AlertDialog with literally just an EditText as its view and two buttons (OK and cancel.)
When there's a problem with the input, I show an error message that ends up being three lines of text, which occludes the OK and cancel buttons. The error text does disappear once the user types something, but I'd sure like the cancel button to be visible.
Is there any (easy) way of changing the placement of the error text?
Unfortunately, not without some customization. The internal PopupWindow managed for the error display is called with showAsDropDown(), which let's Android decide where to display the view in relation to it's anchor (the error icon, in this case) and it will always be below the view unless there is not enough window space. You would have to create (albeit fairly simple) subclass of EditText that displays the internal PopupWindow using showAtLocation() instead.
Here's the link to the TextView source to hopefully help out if you want to try that. The setError() and showError() methods are what you would be after overriding.
HTH
Pretty new to android so excuse me if this is a really obvious question.
Say my application has a bunch of TextViews, each one showing the attributes of a certain product (name, price, etc). I have a button next to each of these TextViews labeled "modify".
How do I make it so that when I press the modify button next to a certain attribute, a popup window with a space to enter text into comes up so that the user can enter text into this box and then have the actual attribute listing on the original page change? Actually I just need a push in the right direction with creating this popup text field... not sure if there is already some built in functionality for this or if not, what would be the best way to create this kind of thing.
Thanks.
Why not have the modify button set TextEdit.setEnabled(true); and then change focus with TextEdit.setFocus? Note that both of these are inherited from view
If you really want a dialog you might want to looking into the AlertDialog.Builder. I know you can use it with buttons and radio buttons, but I'm not sure you can get it to work with a TextView.
Use a code like this for the input popup: Android dialog input text
In the positive button handler, set your edittext content programmatically like this:
myEditText.setText(value).
As simple as that. The only difference with a standard GUI framework is that you don't retrieve the value as a result of the popup function. Instead, you must provide an action handler.