【问题标题】:How to change the textline of an alertdialog in Android如何在 Android 中更改警报对话框的文本行
【发布时间】:2020-09-13 08:57:56
【问题描述】:

有谁知道你如何用 textinput 更改文本输入行和 AlertDialog 的光标(从绿色变为粉红色)。 1]:https://i.stack.imgur.com/1apfI.png 我在我的课堂上这样实现它:


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>

【问题讨论】:

    标签: java android android-alertdialog textinput


    【解决方案1】:

    你可以改变颜色,

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

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

    【讨论】:

      猜你喜欢
      • 2016-04-05
      • 2011-03-08
      • 2016-12-01
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      相关资源
      最近更新 更多