本文介绍了如何编写风格,以错误的EditText文本中的android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写新的自定义样式为我的Andr​​oid应用程序。我需要给风格ERRORTEXT出现在的EditText 设置 SETERROR 之后。

I'm trying to write new custom style for my android application. I need to give style to errorText which appears after setting setError in EditText.

我如何自定义它的风格呢?

How can I customize style of it?

例如:我想设置其背景白色和文字颜色:蓝等等等等,在style.xml

For example: I want to set its background white and textColor: Blue etc etc. in style.xml

推荐答案

解决的办法是在年底,这里是截图:

The solution is at the end and here is the screenshot:

一些解释

您的可能可以使用以下行来设置文本颜色

You might be able to set the textcolor using the following line

yourEditText.setError(Html.fromHtml("<font color='blue'>this is the error</font>"));

不过,这可能无法得到保证。

However, this might not be guaranteed.

据消息人士透露code,这个弹出的节目类型为 ErrorPopup 这是一个内部在的TextView类。这个弹出的内容是一个的TextView com.android.internal.R膨胀.layout.textview_hint

According to the source code, this Popup that shows is of type ErrorPopup which is an internal class inside TextView. The content of this Popup is a single TextView inflated from com.android.internal.R.layout.textview_hint

final TextView err = (TextView) inflater.inflate(com.android.internal.R.layout.textview_hint,
      null);

这样做的背景弹出取决于它是否应该被放在锚点上图:

The background of this Popup depends on whether it should be placed above the anchor:

if (above) {
    mView.setBackgroundResource(com.android.internal.R.drawable.popup_inline_error_above);
} else {
    mView.setBackgroundResource(com.android.internal.R.drawable.popup_inline_error);
}


由于所有用于创建弹出了Android资源内部,并最终硬codeD,你最好的拍摄是创建自己的错误弹出。这将是很容易的,你不会真的是与正常的干扰的EditText 因为默认弹出窗口只是用来显示错误,并因此,创建自己的将没事的。


Since all the android resources used to create the popup are internal and ultimately hard-coded, your best shot would be to create your own error popup. This would be very easy and you wouldn't really be interfering with the normal EditText because the default popup is merely used to show the error, and, thus, creating your own would be fine.

解决方案:

我已经建立在这里: WidgyWidgets

这篇关于如何编写风格,以错误的EditText文本中的android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 04:16