I am trying to open a dialog on widget click. I have solved the problem skinning the activity started on click with android:theme="@android:style/Theme.Dialog"
. Unfortunately I cannot reach the same look of a dialog.
This is the outcome:
Dialog from widget
Instead, I would like to reach this result (except for the button, of course):
Desired dialog from widget
(the widget dialog you can see keeping the screen pushed)
As you can see there are some differences: the color of the list items, the color of the text and the list item separator. Is there a predefined theme/style to obtain the same look of a standard dialog? If not, what are the steps to follow to reach that result?
I have seen that the widget provided by FoxyRing has the behaviour I would like to have.
The custom dialog uses DIALOG to create custom alert in android studio. Dialog display a small window i.e a popup which draws the user attention over the activity before they continue moving forward. The dialog appears over the current window and display the content defined in it.
when a dialog is shown or it's window comes visible on top of an existing activity, then it overrides partial the activity window so existing activity will move to partially invisible state and you will get call to onPause() from ActivityThread. but to be sure we also need to consider here a one think...
Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.
To set the action on alert dialog call the setPositiveButton(), setNeutralButton() and setNegativeButton() methods for positive, neutral and negative action respectively. The show() method of AlertDialog. Builder is used to display the alert dialog.
Why not use a "traditional" Main Activity with a transparent background layout
and call a standard dialog from it ?
... well if I understood you correctly, that would make the trick in a very easy way, isn't it ?
you could dynamically create the dialog like this:
Context mContext = this;
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.data_dialog);
dialog.setTitle("Your title");
AlertDialog.Builder builder;
AlertDialog alertDialog;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.data_dialog,
(ViewGroup) findViewById(R.id.AbsoluteLayout01));
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
alertDialog.show();
final EditText txtUsername = (EditText) layout.findViewById(R.id.txtUsername);
final AlertDialog thisDialog = alertDialog;
Button btnSave = (Button) layout.findViewById(R.id.btnSave);
btnSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String strtxtUsername = txtUsername.getText().toString();
//do something...
}
});
To close the dialog, call thisDialog.dismiss();
The style looks like the regular Theme.Light.NoTitleBar with a ListView with an Icon and a Title-Text.
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With