java - 如何更改 Android 中警报对话框的文本行

标签 java android android-alertdialog textinput

有谁知道如何使用文本输入更改警报对话框的文本输入行和光标(从绿色变为粉红色)。 1]:/image/1apfI.png 我在我的类(class)中实现它是这样的:


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>

最佳答案

您可以通过以下方式更改颜色:

input.getBackground().setColorFilter(getResources().getColor(R.color.pink_cursor), PorterDuff.Mode.SRC_ATOP);

或者

input.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.pink_cursor)));

关于java - 如何更改 Android 中警报对话框的文本行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62024131/

相关文章:

java - 更改 NavigationView 中项目的样式

Java 控制台应用程序

java - 无法使用 DBX 选择器错误创建链接 android

Android alertdialog 自定义布局按钮 onClickListener 崩溃

java - 当触摸在外部时 AlertDialog 消失 [Android]

java - 有什么方法可以使用 mongoDB morphia 从 java 更新/替换 mongoDB 的整个文档?

java - Handle != null 检查两个变量

android - 诸如单元测试和日志记录之类的编程实践在 Android 上重要吗?

javascript - 谷歌云消息 (fake_message_id)

android - 如何将列表动态绑定(bind)到 Android 中的警告框?