I have an EditText inside an AlertDialog. It looks like this.
See where it says tddjdjck and how it is indented quite a lot. That is what I want (I used setPadding
with left and right set to 50), but I also want the blue line under it to be indented too. How do I do that?
The code I am using is below:
final AlertDialog.Builder alert = new AlertDialog.Builder(thisActivity); final EditText input = new EditText(thisActivity); input.setSingleLine(); input.setPadding(50, 0, 50, 0); alert.setTitle("by..."); alert.setMessage("enter the name of the person who did:"); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString().trim(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show();
Thank you
Step 1: Create a XML file: custom_layout. Add the below code in custom_layout. xml. This code defines the alertdialog box dimensions and add a edittext in it.
A simple dialog containing an DatePicker . This class was deprecated in API level 26.
If you only want to change text format, you can just override alertDialogTheme attribute to change the theme for the AlertDialog . <style name="MyTheme" parent="Theme. AppCompat.
final AlertDialog.Builder alert = new AlertDialog.Builder(thisActivity); final EditText input = new EditText(thisActivity); input.setSingleLine(); FrameLayout container = new FrameLayout(thisActivity); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.leftMargin = getResources().getDimensionPixelSize(R.dimen.dialog_margin); input.setLayoutParams(params); container.addView(input); alert.setTitle("by..."); alert.setMessage("test message"); alert.setView(container);
Make sure you add another line to your dimens.xml resource file, such as
<dimen name="dialog_margin">20dp</dimen>
You can pass spacing parameter in setView
method
alert.setView(view ,left_space , top_space , right_space , bottom_space);
So,in your case you can try this
alert.setView(input , 50 ,0, 50 , 0);
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