Why does AlertDialog.Builder(Context context) only accepts Activity as a parameter?

An Activity inherits a Context. AlertDialog.Builder specifies a Context argument because it can then be used by ANY class that is a subclass of Context, including an Activity, ListActivity, Service, … (There is a common coding idiom behind this – you can learn more about it by reading Item I8 (on Interfaces and Abstract classes) … Read more

Dialog buttons with long text not wrapping / squeezed out – material theme on android 5.0 lollipop

This could be fixed with using stacked buttons instead of row buttons. Here my workaround how it could be achieved with using AppCompat lib : Code import android.support.v7.app.AlertDialog; AlertDialog.Builder builder; builder = new AlertDialog.Builder(context, R.style.StackedAlertDialogStyle); builder.setTitle(“Title”); builder.setMessage(“Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dignissim purus eget gravida mollis. Integer in auctor turpis. Morbi … Read more

Blur Background Behind AlertDialog

Update: We can also use renderscript api to blur background for API level >= 17 and uses fastblur for API level < 17. Please find below Github project. – Github Project – Blog Steps Using FastBlur Take the Snapshot of Your Background using Below Code private static Bitmap takeScreenShot(Activity activity) { View view = activity.getWindow().getDecorView(); … Read more

Missing buttons on AlertDialog | Android 7.0 (Nexus 5x)

Indeed it seems that AlertDialog theme needs to be defined. An alternative approach to above would be to define AlertDialog theme in Application theme: <style name=”AppTheme” parent=”Theme.AppCompat.Light.NoActionBar”> <!– … other AppTheme items … –> <item name=”android:alertDialogTheme”>@style/AlertDialogTheme</item> </style> <style name=”AlertDialogTheme” parent=”Theme.AppCompat.Light.Dialog.Alert”> <item name=”colorPrimary”>@color/colorPrimary</item> <item name=”colorPrimaryDark”>@color/colorPrimaryDark</item> <item name=”colorAccent”>@color/colorAccent</item> </style> Then it is enough create AlertDialog.Builder only with … Read more

Android Alert Dialog with one, two, and three buttons

One button import android.support.v7.app.AlertDialog; public class MainActivity extends AppCompatActivity { public void showAlertDialogButtonClicked(View view) { // setup the alert builder AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(“My title”); builder.setMessage(“This is my message.”); // add a button builder.setPositiveButton(“OK”, null); // create and show the alert dialog AlertDialog dialog = builder.create(); dialog.show(); } } Two buttons public class … Read more

Android AlertDialog with rounded corners

You can do it using the following code: CustomDialog.java: public class MainActivity extends Activity{ private static final int ALERT_DIALOG = 1; @Override public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); setContentView( R.layout.main ); ( (Button) findViewById( R.id.button1 ) ) .setOnClickListener( new OnClickListener() { public void onClick( View v ) { showDialog( ALERT_DIALOG ); … Read more

How to put an image in an AlertDialog? Android

Create one sample.xml and add ImageView in that XML. sample.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent”> <ImageView android:id=”@+id/dialog_imageview” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:src=”https://stackoverflow.com/questions/6276501/@drawable/ic_launcher” /> </LinearLayout> Java Code : AlertDialog.Builder alertadd = new AlertDialog.Builder(MessageDemo.this); LayoutInflater factory = LayoutInflater.from(MessageDemo.this); final View view = factory.inflate(R.layout.sample, null); alertadd.setView(view); alertadd.setNeutralButton(“Here!”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sumthin) { } … Read more

AlertDialog with EditText, open soft keyboard automatically with focus on EditText doesn’t work

Ok I managed to get it working: Builder builder = new Builder(this); final EditText input = new EditText(this); builder .setTitle(R.string.dialog_title_addsubject) .setMessage(R.string.dialog_addsubject) .setView(input) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String value = input.getText().toString(); if (input.getText().toString().trim().length() == 0) { Toast.makeText(Main.this, R.string.input_empty, Toast.LENGTH_SHORT).show(); } else { db.insertSubject(value); getData(); } InputMethodManager imm = (InputMethodManager) … Read more

AlertDialog styling – how to change style (color) of title, message, etc

You need to define a Theme for your AlertDialog and reference it in your Activity’s theme. The attribute is alertDialogTheme and not alertDialogStyle. Like this: <style name=”Theme.YourTheme” parent=”@android:style/Theme.Holo”> … <item name=”android:alertDialogTheme”>@style/YourAlertDialogTheme</item> </style> <style name=”YourAlertDialogTheme”> <item name=”android:windowBackground”>@android:color/transparent</item> <item name=”android:windowContentOverlay”>@null</item> <item name=”android:windowIsFloating”>true</item> <item name=”android:windowAnimationStyle”>@android:style/Animation.Dialog</item> <item name=”android:windowMinWidthMajor”>@android:dimen/dialog_min_width_major</item> <item name=”android:windowMinWidthMinor”>@android:dimen/dialog_min_width_minor</item> <item name=”android:windowTitleStyle”>…</item> <item name=”android:textAppearanceMedium”>…</item> <item name=”android:borderlessButtonStyle”>…</item> <item name=”android:buttonBarStyle”>…</item> </style> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)