【问题标题】:How to change color of Text in Error messages in Android Studio?如何在 Android Studio 中更改错误消息中的文本颜色?
【发布时间】:2019-12-04 19:43:37
【问题描述】:

[这是我一直面临的问题,无法在深色模式下更改错误消息。]

如何编辑错误弹出窗口中文本的颜色。当主题和反馈为空且用户尝试发送邮件时,我一直弹出错误消息。

public class FeedBack extends AppCompatActivity {

    EditText subject, body;
    Button send;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);


        send = findViewById(R.id.sendFeedBT);
        subject = findViewById(R.id.subjectET);
        body = findViewById(R.id.bodyTextET);


        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                String subjectSTR = subject.getText().toString().trim();
                String bodySTR = body.getText().toString().trim();

                if(subjectSTR.isEmpty()){

                    subject.setError("Enter a Subject Please");
                    subject.requestFocus();
                }
                else if (bodySTR.isEmpty()){
                    body.setError("Enter the Message Please");
                    body.requestFocus();
                }

                else {

                    Intent email = new Intent(Intent.ACTION_SEND);
                    email.putExtra(Intent.EXTRA_EMAIL, new String[]{"example@gmail.com"});
                    email.putExtra(Intent.EXTRA_SUBJECT, subjectSTR);
                    email.putExtra(Intent.EXTRA_TEXT, bodySTR);
                    email.setType("message/rfc822");
                    startActivity(Intent.createChooser(email, "Choose an Email client :"));
                    finish();
                }
            }
        });
    }
}

【问题讨论】:

    标签: android android-studio text colors android-darkmode


    【解决方案1】:

    您需要创建一个自定义样式,例如:

    <style name="error_text_style" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/error_color</item>
        <item name="android:textStyle">Italic</item>
    </style>
    

    然后设置这个样式。 app:errorTextAppearance="@style/error_text_style"

    【讨论】:

      【解决方案2】:

      定义错误颜色 res/values/colors.xml

      ... ...
      #000000 #002db3 ... ...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-12-11
        • 2021-06-29
        • 2023-01-13
        • 2015-09-19
        • 2021-04-29
        • 2016-09-01
        • 1970-01-01
        相关资源
        最近更新 更多