Java 如何在Android中更改alertdialog的文本行
有人知道如何使用textinput(从绿色变为粉色)更改textinputline和AlertDialog的光标吗。 1]: 我在我的课堂上实现它如下:Java 如何在Android中更改alertdialog的文本行,java,android,android-alertdialog,textinput,Java,Android,Android Alertdialog,Textinput,有人知道如何使用textinput(从绿色变为粉色)更改textinputline和AlertDialog的光标吗。 1]: 我在我的课堂上实现它如下: AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.AlertDialogTheme); builder.setTitle("Artikel Toevoegen"); final EditText input = new Edi
AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.AlertDialogTheme);
builder.setTitle("Artikel Toevoegen");
final EditText input = new EditText(this);
input.setSingleLine();
builder.setView(input);
builder.setPositiveButton("Toevoegen", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(input.length() != 0) {
shoppingList.add((input.getText().toString()));
lv.setAdapter(adapter);
}
else {
Toast toast = Toast.makeText(getApplicationContext(),"Voer een artikel in", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 570);
toast.show();
artikelToevoegen();
}
}
});
builder.setNegativeButton("Annuleer", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 40; //x position
wmlp.y = 100; //y position
dialog.show();
这就是xml样式的外观:
<style name="AlertDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
android:textCursorDrawable="@drawable/pink_cursor"
android:backgroundTint="#D70F64"
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#d70f64</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#d70f64</item>
</style>
android:textCursorDrawable=“@drawable/pink_cursor”
android:backgroundTint=“#D70F64”
@样式/负片按钮样式
@样式/正按钮样式
#d70f64
#d70f64
您可以通过
input.getBackground().setColorFilter(getResources().getColor(R.color.pink_cursor), PorterDuff.Mode.SRC_ATOP);
或
input.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.pink_cursor)));