I wanted to make a Dialog box for simple signup page like this image
but I can't figure out how can I do this. I am basically struggling to make the cross icon to the right corner of the Dialog box.
Is there any library to make this?
Try this:
final Dialog exitBayDialog = new Dialog(getActivity());
exitBayDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
exitBayDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
exitBayDialog.setContentView(R.layout.your_dialog_layout);
final EditText etSearch = (EditText) exitBayDialog.findViewById(R.id.etVehicleNumber);
exitBayDialog.show();
Related
Here is the issue, I want to create a custom alert dialog box with 4 parts,
Title Bar
Header part (Most of the time I plan to use EditText box for
searching purpose)
List item(Single click or Multi Click)
Footer part(Cancel or OK buttons)
I try do this using separate layout, but list view item not showing properly(shrinking). So then I plan to use AlertDialog and inside I have implemented ListView and footer button part in single LinerLayout and set it using setView method, it solved my list view and Footer issue.
Problem is I want to add Header part top of the list view.
Image Link : https://dl.dropboxusercontent.com/u/4048078/device-2013-07-31-141546.png
You can try this
Dialog dialog_help = new Dialog(getActivity());
dialog_help.setContentView(R.layout.title_multi_selectitems_dialog);
EditText et_1 = (EditText) dialog_help.findViewById(R.id.et_help_1);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
dialog_help.setCancelable(true);
dialog_help.setTitle(" Help ");
dialog_help.setCanceledOnTouchOutside(true);
dialog_help.show();
dialog_help.getWindow().setGravity(Gravity.CENTER);
dialog_help.getWindow().setLayout(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
It's not a good practice to set editBox in the title of the alert dialog.
To set title use setTitle and setIcon builder methods.
EditText it the control that's better to place in dialog,s body.
Use AlertDialog.Builder.setView(android.view.View) for this.
I'm looking at the documentation here:
http://developer.android.com/guide/topics/ui/dialogs.html#PassingEvents
And all their examples seem to overlook the developer's potential desire to totally alter the appearance and/or positioning of the OK | Cancel buttons.
I feel like the solution with the DialogFragment comes close, but still there's no obvious way for me to define what View in my activity should BE the OK button, so that I can easily attach the callback to it.
What am I missing? Or is it really not possible to manipulate the appearance and position of the buttons in anything that extends AlertDialog or DialogFragment?
You can use Dialog and add your own custom layout to it and control the appearance of every view in it. Here is an example how you can do this :
final Dialog alert = new Dialog(FingerPaintActivity.this, android.R.style.Theme_Light_Panel);
alert.requestWindowFeature(Window.FEATURE_NO_TITLE); // no title
alert.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation; // this is used for custom animation when dialog is showing and hiding
alert.setContentView(getLayoutInflater().inflate(R.layout.stamps, null)); // here is your custom layout
alert.getWindow().setLayout(width-50, (height-100)); // set height / width
and you can use set listeners to your views (for example a button) like this :
Button myOkBtn = (Button) alert.findViewById(R.id.myOkBtn);
myOkBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
I'm using an AlertDialog with a custom view that contains an EditText widget. I want to change the contents of the EditText widget before the AlertDialog is shown. I know that this is usually done by overriding onPrepareDialog() and setting the text there. However, as far as I can see, this will not work in my specific case because I use AlertDialog.show() instead of Activity.showDialog().
So how should I do this with a dialog that is shown using AlertDialog.show()? One solution is to set the text after the dialog has been brought to the front, i.e.:
AlertDialog alertDialog = builder.create();
alertDialog.show();
EditText editText = (EditText) alertDialog.findViewById(R.id.text);
editText.setText("Foo bar");
However, I don't think that this is a nice solution because the dialog is first shown and then the text is set. I'd like to set the text before the dialog is actually shown.
Is there any way to achieve this? I cannot do it before alertDialog.show() because findViewById() returns null when called before alertDialog.show().
Thanks for any help!
AlertDialog alertDialog = builder.create();
alertDialog.show();
Since you have access to the AlertDialog.Builder object, simply change the layout before calling builder.create().
Addition
I have an EditText widget in my XML file which I inflate using builder.setView(inflater.inflate(R.layout.mydialog, null)). How do I change the text of this EditText widget without calling findViewById()?
Break that line into a series of commands. Specifically: inflate the XML, alter the layout, and pass it to setView().
View view = inflater.inflate(R.layout.mydialog, null);
EditText editText = (EditText) view.findViewById(R.id.text);
editText.setText("Foo bar");
builder.setView(view);
Suppose I have a dialog which is opened from java file . I want to set multiline title of these dialog box.
dialog = new Dialog(context);
dialog.setContentView(R.layout.issue_attachment_preview);
String title=getString(R.string.previewImageDialogTitle)+"\n ["+attachment.filename+"]";
dialog.setTitle(title);
dialog.setCancelable(true);
But it does not display title in multiline , please suggest me any usable link or example.
TextView tv = (TextView) dialog.findViewById(android.R.id.title);
tv.setSingleLine(false);
Add
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
immediately after calling super.onCreate and just before setContentView.
Then add the multiline textview on top of your dialog layout which will work as title
I am trying to put a spinner into an alert box and would much appreciate it, if someone would point me in the direction of a tutorial or show some code on how this can be done.
Create an xml layout with a spinner
in your code:
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.layoutname);
you can access the spinner like this
Spinner spin = (Spinner)dialog.findViewById(R.id.spinnerid);
If you're using an alert dialog, you can add a custom layout containing your Spinner to your existing dialog.
To see an example of this, look for the "DIALOG_TEXT_ENTRY" case in this example: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.html
You can do it like this:
// ProgressBar properties
RelativeLayout.LayoutParams progressParams = new RelativeLayout.LayoutParams(Patterns.PROGRESS_BAR_WIDTH, Patterns.PROGRESS_BAR_WIDTH);
progressParams.addRule(RelativeLayout.CENTER_VERTICAL);
progressParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
mProgress = new ProgressBar(context);
mProgress.setIndeterminate(true);
rootLayout.addView(mProgress,progressParams);
mProgress.setVisibility(View.VISIBLE);
Where rootLayout is your Activity's layout where you want to put the spinning "box". The LayoutParams that I used is just to place the box in the layout's center. When your box is no longer necessary, you can dismiss it like this:
mProgress.setVisibility(View.GONE);
layoutBg.removeView(mProgress);