Show custom alert dialog in Jetpack Compose

Starting from M3 1.1.0-alpha04 there is an AlertDialog composable function with a slot for content. val openDialog = remember { mutableStateOf(true) } if (openDialog.value) { androidx.compose.material3.AlertDialog( onDismissRequest = { // Dismiss the dialog when the user clicks outside the dialog or on the back // button. If you want to disable that functionality, simply use … Read more

Change text color of alert dialog

You have to provide a custom style id in the AlertDialog constructor: AlertDialog.Builder(Context context, int themeResId) and the style file should be something like: <style name=”AlertDialogCustom” parent=”Theme.AppCompat.Light.Dialog.Alert”> <item name=”android:colorAccent”>#0000FF</item> </style>

Android Don’t dismiss AlertDialog after clicking PositiveButton

After looking at @Little Child solution, I try to make this. Let us know if this works for you. AlertDialog.Builder sayWindows = new AlertDialog.Builder( MapActivity.this); final EditText saySomething = new EditText(MapActivity.this); sayWindows.setPositiveButton(“ok”, null); sayWindows.setNegativeButton(“cancel”, null); sayWindows.setAdapter(listWords, null); sayWindows.setView(saySomething); final AlertDialog mAlertDialog = sayWindows.create(); mAlertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = … Read more

Android Image Dialog/Popup

No xml: public void showImage() { Dialog builder = new Dialog(this); builder.requestWindowFeature(Window.FEATURE_NO_TITLE); builder.getWindow().setBackgroundDrawable( new ColorDrawable(android.graphics.Color.TRANSPARENT)); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { //nothing; } }); ImageView imageView = new ImageView(this); imageView.setImageURI(imageUri); builder.addContentView(imageView, new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); builder.show(); }

How to add a check box to an alert dialog

You have to use the method setView(View) on the AlertDialog.Builder object. This will put the passed in View between the message area and buttons. Simply inflate a View with a CheckBox and pass that in. Here’s an example: checkbox.xml <FrameLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”wrap_content” > <CheckBox android:id=”@+id/checkbox” style=”?android:attr/textAppearanceMedium” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_margin=”5dp” /> </FrameLayout> Code in your … Read more

How to set part of text to bold when using AlertDialog.setMessage() in Android?

You need to use Html.fromHtml() too. For example: AlertDialog.setMessage(Html.fromHtml(“Hello “+”<b>”+”World”+”</b>”)); Update: Looks like Html.fromHtml(String source) has been deprecated in the Latest Android Nougat version. Although deprecation doesn’t mean that you need to change your code now, but it’s a good practice to remove deprecated code from your app as soon as possible. The replacement is … Read more

Android-Is it possible to add a clickable link into a string resource

Just use an HTML format link in your resource: <string name=”my_link”><a href=”http://somesite.com/”>Click me!</a></string> You can then use setMovementMethod(LinkMovementMethod.getInstance()) on your TextView to make the link clickable. There is also TextView‘s android:autoLink attribute which should also work.

Getting default padding for AlertDialog

The ?dialogPreferredPadding attribute now has this value. It was introduced in API 22; see https://developer.android.com/sdk/api_diff/22/changes/android.R.attr.html. You can get consistent padding in your custom dialogs by specifying this attribute on the dialog’s layout. For example, android:paddingLeft=”?dialogPreferredPadding” will bring the dialog’s contents into alignment with its title.

AlertDialog with custom view: Resize to wrap the view’s content

I have a working solution that to be honest, I think digs way too deep to obtain such a simple result. But here it is: What exactly is happening: By opening the Dialog layout with the Hierarchy Viewer, I was able to examine the entire layout of the AlertDialog and what exactly what was going … Read more

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