I have alertdialog builder which shows multiChoiceItems, there are many items so all options are not visible and scrollable list is created but scroll bar hides after some seconds. How can I make it visible all the time?
I'm not using custom builder. I know this method but how can I use it setScrollbarFadingEnabled(false)?
You can't do this to a AlertDialog builder. However it is possible to do it to AlertDialog.
Get the AlertDialog from your builder.
AlertDialog dialog = builder.create();
Then you have to show your dialog before you manipulate it.
dialog.show();
Now the methods are available and won't throw errors. Note: You can style your positive and negative buttons here too.
dialog.getListView().setScrollbarFadingEnabled(false);
Related
I'm setting a message in a simple alert dialog. I need to know if the user has read all the text inside the dialog or not. Is there any way to set a scroll listener or something in an alert dialog?
Create your custom dialog and then set some listener to your custom View. Here's a good example: http://www.mkyong.com/android/android-custom-dialog-example/
and
https://stackoverflow.com/a/10713501
There is a way to set the 'black' background size of the alertDialog?
I'm not meaning the size of the alertDialog but of his background that cover all the display.
I have an alert dialog that appears in a fragment where it has some tabs, the problem of the background of the alertdialog is that cover all the display, so i cannot tap on the tabs.
AlertDialog docs and AlertDialogBuilder docs say that it is possible to change background - via AlertDialog(Context context, int theme) constructor for example, or providing Your own view for AlertDialogBuilder.
But I'm not sure if that's what You want - whole point of AlertDialog is to...be displayed for user to take action, so yes, it occludes Your fragments why wouldn't it? From Your post it looks like You are trying to move to other fragment while AlertDialog is displayed, if I understood correctly. But if just reading what's under - probably AlertDialogBuilder with custom view is way to go.
Suppose you have an AlertDialog with two buttons A and B. I have found that on some devices and some versions of android, if you touch any area of the screen around the dialog, the AlertDialog disappears. On other devices you are forced to select either A or B, so there is no way I can allow the user to cancel the action without adding a third ('Cancel') option to the AlertDialog. Is there any way to determine programmatically whether the third option is required?
You can control it with dialog.setCanceledOnTouchOutside(true);
For more information :
How to dismiss the dialog with click on outside of the dialog?
Dialog dialog = new Dialog(context)
dialog.setCanceledOnTouchOutside(true);
I am writing an Android app where I need to put bigger text on the Buttons of Dialog windows programatically.
I saw that there are two options to set (positive, negative or neutral) buttons on an AlertDialog.Builder:
setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener)
setPositiveButton(int textId, DialogInterface.OnClickListener listener) and
In option 1, I can only set the text and in option 2, I can use resource id of the text value.
But none of the options allow me to add a styled button.
Is there some other way?
There is no need for you to create a custom view.
The dialog builder create method returns a AlertDialog object that gives you access to the buttons.
AlertDialog.Builder alert = new AlertDialog.Builder(YOUR_CONTEXT);
AlertDialog dialog = alert.create();
// Positive
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(THE_SIZE);
// Negative
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextSize(THE_SIZE);
OF course, you can always go for your custom View to show to the user when the dialog is created, by using:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(yourCustomView);
However, take on count that creating your own custom View, means you have to inflate your own layout, create your buttons inside of it and handle the proper click actions, just like you do in a regular activity, this is the way to go if you want to modify any of the "default" views in your dialog...
Hope this helps...
Regards!
I'm developing an Android 2.2 application.
I want to show a text with an Ok button but I want to add my custom style.
What is the better choice an AlertDialog with a custom layout or a Dialog?
I'd go for AlertDialog:
It's easier to implement.
The only custom thing you have to do is an XML layout and then inflate it.
AlertDialog dialog = new AlertDialog.Builder(this)
.setView(getLayoutInflater().inflate(R.layout.custom_dialog, null))
.create();
In order to listen for UI events:
View view = getLayoutInflater().inflate(R.layout.custom_dialog, null);
Button btn = (Button)view.findViewById(R.id.the_id_of_the_button);
btn.setOnClickListener(blah blah);
AlertDialog dialog = new AlertDialog.Builder(this)
.setView(view)
.create();
You can check in android dialog docs:
The Dialog class is the base class for dialogs, but you should avoid instantiating Dialog directly. Instead, use one of the following subclasses:
AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .
when would i use an Alert Dialog?
-When i just want to inform something to the user .
-When we want use for a prompt like Do you want to go back (Yes, No, Cancel. Alert dialog comes with 3 buttons which are positive, negative and neutral which are provided by default).
-When i want to prompt user for a simple value (number/date/string...)
when would i use a Dialog?
-When i want to carry on a complex process with more buttons and widgets .
-Example: