How to display title of dialog in multi line? - android

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

Related

Is there a way when displaying a dialog in Android to tell the app to show the pop up?

I have a full screen app that has buttons that want to have a custom drop down when they are clicked. I was thinking of having a custom dialog show up that will have the options. Is there a way to tell the dialog where to show up?
If you want to create a Dialog window you can change the position of the screen in which it will be displayed by doing something like this:
//Dialog reference
Dialog dialog;
//Instantiate here your dialog
dialog = ... ;
//Get window layout parameters reference
Window window = dialog.getWindow();
WindowManager.LayoutParams windowLayoutParams = window.getAttributes();
//Set the parameters you want
windowLayoutParams.gravity = Gravity.CENTER; //e.g. dialog's will be centered
window.setAttributes(windowLayoutParams);
You can instead use Gravity.BOTTOM or Gravity.TOP to display the dialog accordingly. Alternatively, for more specific positioning you can try setting attributes "windowLayoutParams.x" & "windowLayoutParams.y".

having trouble to make the layout of a dialog box

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

Changing contents of an EditText widget in AlertDialog without onPrepareDialog()

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

Change new text view inside of a dialog

I built a linear layout inside of a dialog , the problem here that i want to change the TextView of this layout but i don't know how ! ,, any help ?
The same way you would do it with a normal view.
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText("Hello");

How to get a spinner into an alertbox/dialog?

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

Categories

Resources