Feed Buzzard
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact
No Result
View All Result
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact
No Result
View All Result
Feed Buzzard
No Result
View All Result
Home World Tech

Add bigger margin to EditText in lertDialog –

Gordon James by Gordon James
January 9, 2021
in World Tech
0
0
SHARES
7
VIEWS
Share on FacebookShare on Twitter

Development issue/problem:

I have an EditText in an AlertDialog. That’s what it looks like.

See where tddjck is and how many prints there are. That’s what I want (I used setPadding, setting left and right to 50), but I also want the blue line underneath it to be indented. How can I do that?

The code I used is below:

last warning AlertDialog.Builder = new AlertDialog.Builder(thisActivity) ;
last entry EditText = new EditText(thisActivity) ;
entry.setSingleLine() ;
entry.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 null and 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 very much.

How can I solve this problem?

Solution 1:

last warning AlertDialog.Builder = new AlertDialog.Builder(thisActivity);
last EditText entry = new EditText(thisActivity);
entry.setSingleLine();
FrameLayout container = new FrameLayout(thisActivity);
FrameLayout.LayoutParams parameter = 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 source file, for example. B.

20p.

Solution 2:

The interval parameter can be passed using the setView method.

alert.setView(view, left_space, top_space, right_space, bottom_space) ;

In your case, you might want to try

alert.setView (input, 50.0, 50.0) ;

Solution 3:

There is a Kotlin extension here that allows the constructor to define the EditText view.

Val Float: Int
get() = (the * Resources.getSystem().displayMetrics.density).toInt()

fun AlertDialog.Builder.setEditText(editText : EditText) : AlertDialog.Builder {
fall container = FrameLayout(context)
container.addView(editText)
fall containerParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT
)
fall marginHorizontal = 48F
fall marginTop = 16F
containerParams.topMargin = (marginTop / 2).toPx
containerParams.leftMargin = marginHorizontal.toInt()
containerParams.rightMargin = marginHorizontal.toInt()
container.layoutParams = containerParams.

fall superContainer = FrameLayout(context)
superContainer.addView(container)

setView (supercontainer)

give this back
}

Example of use

val editText = EditText(this)
AlertDialog.Builder(this)
.setTitle(Group Name)
.setEditText(editText)
.setPositiveButton(OK, { _ : DialogInterface, _ : Int ->
// Work with text here
val text = editText.text.toString()
Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
})
.setNegativeButton(Cancel, null)
.show()

Result

Solution 4:

I’m creating a generic single-entry AlertDialog function. The code speaks for itself.

Give here a description of the image

Utils.java.

Used community class

/**
* dp in px-Wert umrechnen.
* –
* Quelle: https://stackoverflow.com/a/6327095/2263329
*/
public static int dpToPx(float dp, Resources) {
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
return (int) px;
}.

/**
* Advanced dialogue with an Eingabeld at this time.
*
* @param context Anwendungskontext
* @param title Dialog title
* @param message Dialogeingabe Nachricht/Tipp
* @param inputType EingabeTyp von EditText
* @param positiveBtnText Dialogue positiveBtnText
* @param negativeBtnText negativeBtnText
* @param listener Dialogbuttons click listener
*/
public static emptiness showSingleInputDialog(
@NonNull Context),
@NonNull String title,
@NonNull String message,
int inputType,
@NonNull String positiveBtnText,
@NonNull String negativeBtnText,
@NonNull last SingleInputDialogListener listener
) {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle(title);

TextEingabeLayout textEingabeLayout = new TextEingabeLayout (context);

last EditText input = new EditText(context);
input.setSingleLine(true);
input.setInputType(inputType);
input.setHint(message);

FrameLayout container = new FrameLayout(context);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

int left_margin = Utils.dpToPx(20, context.getResources());
int top_margin = Utils.dpToPx(10, context.getResources());
int right_margin = Utils.dpToPx(20, context.getResources()));
int bottom_margin = Utils.dpToPx(4, context.getResources());
params.setMargins(left_margin, top_margin, right_margin, bottom_margin);

textInputLayout.setLayoutParams(params);

textInputLayout.addView(input);
container.addView(textInputLayout);

alert.setView(container);

alert.setPositiveButton(positiveBtnText, new DialogInterface.OnClickListener() {
public null and void onClick(DialogInterface dialogue, int whichButton))) {

listener.positiveCallback(input.getText().toString());

}
});

alert.setNegative button (negativeBtnText,
new DialogInterface.OnClickListener() {
public null onClick(DialogInterface dialogue, in which)) {

listener.negativeCallback();

}
});

alert.show();
}

}

SingleInputDialogListener.java

SingleInputDialogListener public interface {

void positiveCallback(String inputText);

null negativeCallback();

}

Spoil you an image:

Utils.showSingleInputDialog(mContext,
Passwort recuperate,
Ihre E-Mail-Address,
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS,
Recuperate,
Abort,
new SingleInputDialogListener() {
@Alle
public void positiveCallback(String inputText)) {

Toast.makeText(mContext, inputText, Toast.LENGTH_SHORT).show();

}

@Override
public void negativeCallback() {

// …

}
});

Solution No 5:

Floating fillingDp = 1 in fillingPx = 5;

paddingPx = (int)TypedValue.ApplyDimension (ComplexUnitType.Dip,
paddingDp, activity.Resources.DisplayMetrics);
//
adDialog.SetView(input, paddingPx, 5, paddingPx, 5);

Please try the following extension
I made it for xamarin android, hopefully it will also work with light changes for Java.

Public static AlertDialog ShowInputDialog (this activity, string name, string message, txtValue string, dismissButtonText string, submitButtonText string, Action OnSubmit,bool TextInputType =false,bool isEdittable =true){AlertDialog adDialog = null;try{adDialog = new AlertDialog.Builder(activity).Create();// TextViewEditText erstellen input = new EditText(activity);input.ImeOptions = Android.Views.InputMethods.ImeAction.Done;input.Enabled = isEdittable;float paddingDp = 1 int paddingPx = 5;if (!TextInputType){input.SetBackgroundResource(Resource.Color.edit_text_shape);input.InputType = Android.Text.InputTypes.ClassNumber | Android.Text.InputTypes.NumberFlagDecimal;input.Text = txtValue;//input.SetMaxLines(5);//input.SetLines(5);}.more{input.SetBackgroundResource(Resource.Color.edit_text_shape);

// Umrechnung in Pixel
paddingPx = (int)TypedValue.ApplyDimension (ComplexUnitType.Dip, paddingDp, activity.Resources.DisplayMetrics);
input.SetPadding(paddingPx, paddingPx, paddingPx);

Input.Text = txtValue;
input.SetMaxLines(5);
input.SetLines(5);
}
//input.FocusChange += (object transmitter, View.FocusChangeEventArgs e) =>
//{
///Software-Tastatur anfordern.
// InputMethodManager imm = (InputMethodManager) activity.GetSystemService (Context.InputMethodService);
// if (e.HasFocus)
// imm.ToggleSoftInput (ShowFlags.Forced, HideSoftInputFlags.None);
//}

input.EditorAction += (s, e) =>
{
if (e.ActionId == ImeAction.Done)
{
adDialog.Hide();
adDialog.Cancel();

if (OnSubmit != null)
OnSubmit(input.Text);

}

};

//adDialog.Window.ClearFlags.NotFocusable | WindowManagerFlags.AltFocusableIm);
adDialog.SetTitle(title);
adDialog.SetMessage(message);
adDialog.SetView(input, paddingPx, 5);
adDialog.SetButton(dismissButtonText, new EventHandler(
(s, args) =>
{
adDialog.Hide();
adDialog.Cancel();

View = adDialog.CurrentFocus;
if (view != null)
{
InputMethodManager imm = (InputMethodManager)activity.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(view).WindowToken, HideSoftInputFlags.None);
}
});
adDialog.SetButton2(submitButtonText, new EventHandler(
(s, args) =>
{
as (OnSubmit != null)
OnSubmit(input.Text);

View = adDialog.CurrentFocus;
if (view != null)
{
InputMethodManager imm = (InputMethodManager)activity.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(view.WindowToken, HideSoftInputFlags.None);
}
}))));
adDialog.Window.Attributes.WindowAnimations = Resource.Style.DialogAnimation_2;

adDialog.Show();
//input.RequestFocus();
SetDialogTheme(activity, adDialog);
}
catch (exception – ex)
{
throw – ex;
}
returnDialog;
}

Suitability for activities:

this.ShowInputDialog(Name, , Textnotizen bearbeiten, Rückgängig, Speichern, async (fall) =>
{
try
{
//handle zum Speichern

}
catch (Exception – ex)
{

}
}, true);

Fell Glück!

Related Tags:

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0
Gordon James

Gordon James

James Gordon is a content manager for the website Feedbuzzard. He loves spending time in nature, and his favorite pastime is watching dogs play. He also enjoys watching sunsets, as the colors are always so soothing to him. James loves learning about new technology, and he is excited to be working on a website that covers this topic.

Related Posts

Blockchain Conference in Poland Showcases New Solutions to Problems in Enterprise Logistics
World Tech

Blockchain Conference in Poland Showcases New Solutions to Problems in Enterprise Logistics

December 15, 2022
World Tech

Rockstar Games Brings GTA to The Metaverse

October 20, 2022
World Tech

Ways Technology Is Changing The World Of Education

September 21, 2022
Next Post

How to measure height, width and distance of object using camera? –

Fixing Error Fatal: Origin does not appear to be a Git Repository

5 Best Sites Like MovieTube to Watch Movies Online Free

No Result
View All Result

Recommended

Myths and Misconceptions About Joint Pain

Myths and Misconceptions About Joint Pain

6 hours ago
The Spider Veins Facts that Every Individual Ought to Know

The Spider Veins Facts that Every Individual Ought to Know

6 hours ago

5 Benefits of Telehealth That You Should Understand

16 hours ago
openai gpt3 dallmiddotdouglas mit technologyreview

Why GPT-3 is so Impressive – and Why it’s Also Worrying

24 hours ago

Categories

  • Fitness Trackers
  • General
  • Latest
  • Pokemon
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

Recent Posts

  • Myths and Misconceptions About Joint Pain January 30, 2023
  • The Spider Veins Facts that Every Individual Ought to Know January 30, 2023
  • 5 Benefits of Telehealth That You Should Understand January 30, 2023
  • Why GPT-3 is so Impressive – and Why it’s Also Worrying January 29, 2023

Categories

  • Fitness Trackers
  • General
  • Latest
  • Pokemon
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

© 2022 FeedBuzzard.com

No Result
View All Result
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT