I have tried many variants to create full screen dialog but I couldn't. I need something, like this, with two buttons:
If you really want a a fullscreen dialog just extend the Dialog class and add a few tweaks. (You can also accomplish this without extending anything, but I thought you might want to keep everything in one place)
In your constructor you need to set the style (for your material look, or it can be an empty style tag):
super(context, R.style.DialogStyle);
you also need to set the view: (This is where you would define where/what those two buttons are)
setContentView(R.layout.dialog_view);
Finally, you might also need to modify the windows layout parameters:
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
I have found on the devices I have tested that setting the style is the most important.
*EDIT*
To make it a little more clear you have two options:
public class MyDialog extends Dialog {
public MyDialog(Context context) {
super(context, R.style.YourStyle);
setContentView(R.layout.dialog_view);
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); //Optional
//Any other code you want in your constructor
}
}
Then when you want to show it:
//Inside your activity
MyDialog dialog = new MyDialog(this); //Assuming you are in an activity 'this' is your context
dialog.show();
Or you can just do this:
Dialog normalDialog = new Dialog(this, R.style.YourStyle);
normalDialog.setContentView(R.layout.dialog_view);
normalDialog.show();
I agree with using a new activity. Set the HomeAsUp indicator to whatever you want, then the Save button could be a single menu item set to show ifRoom.
http://developer.android.com/reference/android/app/ActionBar.html#setHomeAsUpIndicator(int)
android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]
This is what I use to display a full screen dialog without action bar:
//Display fullscreen without actionbar
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Holo_Light_NoActionBar_Fullscreen);
} else {
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_NoActionBar_Fullscreen);
}
Related
As mentioned here, under the different types of Dialogs, the Simple Dialog is listed. Is there a dialog builder that would automatically generate such dialog? Is it just an alert dialog with a custom theme?
I would like to replicate a dialog similar to the new permissions dialogs used in Android 10.
I have tried using the material alert dialog builder:
new MaterialAlertDialogBuilder(context)
.setTitle("Title")
.setMessage("Message")
.setPositiveButton("Ok", null)
.setNegativeButton("Ok", null)
.show();
But this shows the options horizontally, whereas I would like to have them vertically. I have many custom dialogs in my app so I could create another one exactly as I need it, but I wanted to get a better understanding of what's ready to use with the material components instead.
For that reason I downloaded the material-components-android project from github, where I found the DialogMainDemoFragment which lists different types of dialogs. The one that is closer to what I want is created like so:
addDialogLauncher(
dialogLaunchersLayout,
R.string.long_title_message_too_long_actions,
new MaterialAlertDialogBuilder(getContext())
.setTitle(getResources().getString(R.string.long_title))
.setMessage(message)
.setPositiveButton(getResources().getString(R.string.too_long_positive), null)
.setNegativeButton(getResources().getString(R.string.too_long_negative), null)
.setNeutralButton(getResources().getString(R.string.too_long_neutral), null));
where
private void addDialogLauncher(
ViewGroup viewGroup, #StringRes int stringResId, AlertDialog.Builder alertDialogBuilder) {
MaterialButton dialogLauncherButton = new MaterialButton(viewGroup.getContext());
dialogLauncherButton.setOnClickListener(v -> alertDialogBuilder.show());
dialogLauncherButton.setText(stringResId);
viewGroup.addView(dialogLauncherButton);
}
but I can't see where the styling/theming is being determined.
There is material theme which values you can override.
Exactly if I not mistaken you need those styles
<style name="MaterialAlertDialog.MaterialComponents.Title.Panel.CenterStacked" parent="Base.MaterialAlertDialog.MaterialComponents.Title.Panel">
<item name="android:orientation">vertical</item>
</style>
I am using a third party library: SingleDateTimePicker https://github.com/florent37/SingleDateAndTimePicker
This is a great way to display a dialog at the bottom of the screen of date and time. This is how I am doing it:
new SingleDateAndTimePickerDialog.Builder(getContext())
.displayMinutes(false)
.bottomSheet()
.curved()
.displayListener(new SingleDateAndTimePickerDialog.DisplayListener(){
#Override
public void onDisplayed(SingleDateAndTimePicker picker) {
System.out.println("displayed");
}
})
.title("Select Time")
.listener(new SingleDateAndTimePickerDialog.Listener() {
#Override
public void onDateSelected(Date date) {
System.out.println(date.toString());
...
...
}
})
.display();
My only issue here is that when the picker pops up the back screen does not darken to emphasize the popup (like a dialog fragment). Is there a way to darken the background manually?
I tried to put the above library in a layout of its own and inflate it from a DialogFragment, however with this approach I am not sure how to call onDateSelected to get the date
(at the same time, DialogFragment impose certain layout parameters like, the dialog has to be in the middle of the screen and cannot have a width that match_parent. That is why I don't think that putting this in a Dialog Fragment is the way to go)
Note: the non-picker area is clickable. i.e. when clicked the picker area disappears
This is what I have:
This is what I want:
use this will take your application style :
https://github.com/Kunzisoft/Android-SwitchDateTimePicker
Which component do I choose to achieve custom dialog at the bottom as shown in the below image? Shall I choose alertdialog,popupwindow, or fragmentdialog?
Try this
BottomSheetDialog dialog = new BottomSheetDialog(YourActivity.this);
dialog.setContentView(YourView);
dialog.show();
Edit: I didn't there was a built in component in Android to do so. Good to know! Also, check this out:
https://medium.com/glucosio-project/moving-from-dialogs-to-bottomsheetdialogs-on-android-15fb8d140295#
I would recommend FragmentDialog without a doubt.
It's so much easier to create a customized Dialog regarding location & layout design.
Kotlin code for run custom ButtomSheetDialog (run inside Activity)
var CustomSelectProfilePicBottomSheetDialog = BottomSheetDialog(this)
val layoutButtomSheetView = this.layoutInflater.inflate(R.layout.ly_custom_buttom_sheet_frg_dialog, null)
CustomSelectProfilePicBottomSheetDialog.setContentView(layoutButtomSheetView)
CustomSelectProfilePicBottomSheetDialog.show()
First, I will like to give a big Kudos to Stuart Lodge for this awesome framework. Together with Xamarin's Visual Studio integration, this is one of the most productive cross platform frameworks I have laid my hands on.
What I want to achieve is launch a dialog containing a selectable ListView when a button is clicked. I need access to the selected item when the user closes this dialog. Is there a recommended way to do this using the Mvvmcross' dialog plugin while following the MVVM paradigm?
I am using the following Activity to create a dialog.
[Activity(Theme = "#android:style/Theme.Holo.Dialog")]
public class SearchResultDialogView : MvxActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.SearchResultView);
}
}
Navigating to SearchResultDialogViewModel from another view model brings up this view as modal. So it looks like I am heading in the right direction. However, the dialog is missing the OK and Cancel buttons and I will also like to get rid of the default header. Think I need an AlertDialog but so far I have had no success launching one with this code:
[Activity(Theme = "#android:style/Theme.NoTitleBar")]
public class SearchResultDialogView : MvxActivity
{
protected override Dialog OnCreateDialog(int id, Bundle args)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetTitle("some title");
return builder.Create();
}
}
Apologies if this question is vague. I am new to Android UI development.
TIA.
There are several different uses of the word dialog here.
Android Dialogs are 'popup displays' and are covered in http://blog.ostebaronen.dk/2013/02/using-dialogs-in-mono-for-android.html
The MvvmCross Dialog plugin is a code-based form-builder forked from the existing MonoDroid.Dialog and MonoTouch.Dialog tools - see https://github.com/migueldeicaza/MonoTouch.Dialog
The Holo Dialog display is (actually I'm not sure) some theme-based skin on a normal Activity.
With these in mind...
If you want to display a general popup window to collect some data, then you can try using a fragment based dialog to collect data - this is demonstrated (with a little code behind) in Fragments HomeView.cs with NameDialogFragment.cs - for general background on fragments, watch N=26 in http://mvvmcross.wordpress.com/
If you want to use a separate activity for data collection, then #gschackles wrote this article on one way of returning data from child viewmodels - http://www.gregshackles.com/2012/11/returning-results-from-view-models-in-mvvmcross/ - I'm sure other schemes could also be used.
If you do want to learn about the Mvx Dialog plugin, see N=23 in http://mvvmcross.wordpress.com/
You can do it with the builder.
http://developer.android.com/guide/topics/ui/dialogs.html#AddingAList
The code is:
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.pick_color);
.setItems(R.array.colors_array, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
}
});
return builder.create();
}
and you can get your element by returning the which value to your caller.
I am managing multiple custom dialogs in a LinkedList.
The first dialog that was shown always has FLAG_DIM_BEHIND set and all the other shown dialogs have FLAG_DIM_BEHIND cleard from thier flags.
My problem is that the dialogs are not influenced by the FLAG_DIM_BEHIND affect of firstDialog and I think it is because firstDialog is created first.
I tried the following methods:
Using firstDialog.getWindow().getDecorView().bringToFront() => didn't work
Canceling all the dialogs and than reshowing them when the firstDialog is shown last. But when I canceled the windows, they got removed from the LinkedList.
Dismissing all the dialogs and than reshowing them when firstDialog is shown last. But the dialogs just don't reshow.
....
LinkedList<CustomDialog> dialogList = new LinkedList<CustomDialog>();
CustomDialog firstDialog = new CustomDialog();
firstDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialogList.add(firstDialog);
CustomDialog temp;
for(int i = 0; i < 3; i++)
{
temp = new CustomDialog();
temp.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialogList.add(temp);
}
for(CustomDialog itr : dialogList)
{
itr.show();
}
....
Thank you very much in advance.
I use multiple dialogs over each other in my app, but use them in separate classes.
public class PopFilters extends Dialog implements android.view.View.OnClickListener{}
and call them by this
PopFilters(NewMain.nmain).show();
The problem I have is when the phone is oriented in portrait using
FLAG_DIM_BEHIND
it causes the dialog to flicker when opening, when in landscape, no problem. It drives me crazy, but other than that no issues.