Я пытаюсь создать Диалоговое окно оповещения, например Lollipop, все идет хорошо, но я застрял в одном разделе в случае EditText.
Мне нужен EditText с подчеркиванием и полем слева и справа с 20dp. Для подчеркивания я попробовал setBackground() , и он работает нормально.
Но есть проблема, что setBackground() не будет работать API Level ниже 16.
Для setMargin я пробовал
final EditText input = new EditText(MainActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(30,0,30,0);
input.setLayoutParams(lp);
input.setGravity(View.TEXT_ALIGNMENT_GRAVITY);
input.setBackground(getResources().getDrawable(R.drawable.edit_text_line));
builder.setView(input);
Но редактируйте текст, используя полную родительскую ширину.
Полный код
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Message");
builder.setMessage("Do you want to\n"+""+"exit from app");
final EditText input = new EditText(MainActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(30,0,30,0);
input.setLayoutParams(lp);
input.setGravity(View.TEXT_ALIGNMENT_GRAVITY);
input.setBackground(getResources().getDrawable(R.drawable.edit_text_line)); //call reequires api 16 and above
builder.setView(input);
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "You exit from app " + input.getText().toString(),
Toast.LENGTH_LONG).show();
}
});
AlertDialog alert = builder.create();
alert.show();
Button nbutton = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
nbutton.setTextColor(Color.parseColor("#7e7e7e"));
Button pbutton = alert.getButton(DialogInterface.BUTTON_POSITIVE);
pbutton.setTextColor(Color.parseColor("#109c8f"));
Есть ли способ установить background для EditText, который работает ниже API 16, и setMargin слева и справа для EditText сильный>.