android-alertdialog

Android: intercepting back key

偶尔善良 提交于 2019-12-23 15:36:10
问题 since the back key destroys my application and all data will be lost I need to intercept it to ask the user if that is really what he wants. I thought of the following structure: @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // ask user if he really wants to exit // no --> return true; // yes --> return super.onKeyDown(keyCode, event); //manually entering either of the return values works fine } return

How can I customize the header layout of a dialog

孤街醉人 提交于 2019-12-23 15:33:15
问题 In Android, is it possible to customize the header layout (the icon + a text) layout of a dialog? Or can I just set a custom string value of the title text? Thank you. 回答1: It's possible to change the header of the Dialog if you set a custom layout for both the dialog and the header. I've only ever used this method to remove the header entirely, but this ought to work for a custom header: dialog = new Dialog(context); Window window = dialog.getWindow(); window.requestWindowFeature(Window

Set text in TextView in custom dialog

若如初见. 提交于 2019-12-23 12:57:10
问题 I want to set the text in a TextView contained in a custom dialog programmatically, so that I can use Html.fromHtml . In what function should I call setText ? I've tried doing it in onCreateDialog , but this does not actually change the text. public class InfoDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

Set text in TextView in custom dialog

前提是你 提交于 2019-12-23 12:56:01
问题 I want to set the text in a TextView contained in a custom dialog programmatically, so that I can use Html.fromHtml . In what function should I call setText ? I've tried doing it in onCreateDialog , but this does not actually change the text. public class InfoDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

AlertDialog AppCompat width and height

ぃ、小莉子 提交于 2019-12-23 12:39:05
问题 My custome style for AlertDialog look like: <style name="Testing.Dialog" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="colorAccent">@color/color_accent</item> <item name="android:textColorPrimary">@color/text_color_primary</item> <item name="android:background">@color/color_primary</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> </style> I need change width and height, because it is too large on my tablet. Any ideas?

Alert Dialog background theme/Color

让人想犯罪 __ 提交于 2019-12-23 12:08:17
问题 I want to set AlertDialogue theme or change background color. Though I know it has a default theme but in different version I am getting different theme so I want to fix it for all version. Or simply change background color as white @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { final SimpleAdapter adapter = new SimpleAdapter(getContext(), imagesWithNames, R.layout.lib_dialog_image, new String[]{"name", "imageID","Spacing"}, new int[]{R.id.text1, R.id.image1,R.id.spacing})

How to style buttons in Alert Dialog Fragment using Material Design?

白昼怎懂夜的黑 提交于 2019-12-23 09:48:49
问题 I'd like to change the default button styling on an alert dialog. The standard Alert Dialog Fragment (in Android L) looks like this: I'd like the right button to be styled as a normal button instead of a borderless button. Google itself seems to use this pattern in various dialogs, such as: Does anyone know if this is possible, without recreating the whole dialog from scratch? 回答1: You can style the button in the theme with attributes: android:buttonBarPositiveButtonStyle , android

Robolectric InflateException when using v7 support library AlertDialog

回眸只為那壹抹淺笑 提交于 2019-12-23 09:48:40
问题 Using a normal android.app.AlertDialog works with ShadowAlertDialog.getLatestAlertDialog() , but if you use a support library android.support.v7.app.AlertDialog , then this exception happens: android.view.InflateException: XML file app/build/intermediates/res/qa/debug/layout/abc_alert_dialog_material.xml line #-1 (sorry, not yet implemented): Error inflating class android.support.v7.internal.widget.DialogTitle at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) at

AlertDialog: Why can't I show Message and List together?

折月煮酒 提交于 2019-12-23 06:48:36
问题 Does anybody know why the AlertDialog doesn't show the list of items when I add a Message with .setMessage() ? The negative and positive buttons will be shown, but not the list. When I delete the line with .setMessage() everything works. This is my code: AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this.getActivity()); myAlertDialog.setTitle("Options"); myAlertDialog.setMessage("Choose a color."); CharSequence[] items = {"RED", "BLUE", "GREEN" }; myAlertDialog

How to open Dialog Box when broadcast receive in android?

不羁岁月 提交于 2019-12-23 04:59:16
问题 How to open Dialog when phone state is receive. Because whenever a State is received it results in the following error: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application How can I solve this problem? Phone State is Idle then i call Dialog. Any help will be appreciated. Here is my code. final Dialog dialog = new Dialog(mcontext); dialog.setContentView(R.layout.dialog); dialog.setTitle("Android Custom Dialog Box"); final EditText et