Show dialog activity over another app from background

In order to have a dialog activity shown over another application, a few things must be done: The dialog activity must have a translucent theme, to allow the other application to show up behind it (see @android:style/Theme.Translucent.NoTitleBar) The dialog activity must not fill the screen, for the same reason (see Window.setLayout) The dialog activity must … Read more

AlertDialog with positive button and validating custom EditText

Dialog creation: AlertDialog.Builder builder = new AlertDialog.Builder(YourActivity.this); builder.setCancelable(false) .setMessage(“Please Enter data”) .setView(edtLayout) //<– layout containing EditText .setPositiveButton(“Enter”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //All of the fun happens inside the CustomListener now. //I had to move it to enable data validation. } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); Button theButton = … Read more

How do I fire an event when click occurs outside a dialog

When dialog.setCanceledOnTouchOutside(true); then you just override onCancel() like this: dialog.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { //When you touch outside of dialog bounds, //the dialog gets canceled and this method executes. } } ); Type your code inside the onCancel() method so it runs when the dialog gets canceled.

How to make custom dialog with rounded corners in android

Create an XML file in drawable, say dialog_bg.xml: <?xml version=”1.0″ encoding=”utf-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android”> <solid android:color=”@color/white”/> <corners android:radius=”30dp” /> <padding android:left=”10dp” android:top=”10dp” android:right=”10dp” android:bottom=”10dp” /> </shape> set it as the background in your layout XML: android:background=”@drawable/dialog_bg” Set the background of the dialog’s root view to transparent, because Android puts your dialog layout within a root view … Read more

findViewById() returns null for Views in a Dialog

Calling findViewById() will search for views within your Activity’s layout and not your dialog’s view. You need to call findViewById() on the specific View that you set as your dialog’s layout. Try this private void initSearch() { AlertDialog.Builder searchDialog = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); searchDialog.setTitle(“Search Photos”); searchDialog.setMessage(“Specify tag and value…”); // R.layout.search_dialog is … Read more

Change background of ProgressDialog

The comment of Aleks G (below the question) points in the right direction. The appearance of the dialog is defined by a separate style (android:alertDialogStyle). But one cannot apply the style directly to a ProgressDialog. Now, how do I get that yellow background? Step 1: Define a theme that inherits from Theme.Dialog: <style name=”MyTheme” parent=”@android:style/Theme.Dialog”> … Read more

How to create a number picker dialog?

I have made a small demo of NumberPicker. This may not be perfect but you can use and modify the same. public class MainActivity extends Activity implements NumberPicker.OnValueChangeListener { private static TextView tv; static Dialog d ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.textView1); Button b = (Button) findViewById(R.id.button11); b.setOnClickListener(new … Read more