0

我在某些条件下(使用形状)将红色边框添加到编辑文本,并且在我想回到默认的 android 样式编辑文本之后。

我试过这样:

EditText lastName = FindViewById<EditText>(Resource.Id.lastName);
lastName.SetBackgroundResource(Android.Resource.Drawable.EditBoxBackgroundNormal);

它显示长白条而不是默认样式的edittext(黑色背景和灰色线条)。

如何获得这种默认样式的 edittext ?

4

2 回答 2

1

您如何设置“错误”标志?我不会删除背景,而是Drawable将其设置为:

myEditText.SetCompoundDrawablesWithIntrinsicBounds(0 , 0, Resource.Drawable.MyErrorIcon, 0);

Where myEditTextis an instance of EditTextand Resource.Drawable.MyErrorIconis aDrawable您要显示的图标。

您可以使用以下方法将其删除:

myEditText.SetCompoundDrawablesWithIntrinsicBounds(0 , 0, 0, 0);

通过设置,CompoundDrawables您将永远不需要触摸EditText.

于 2013-04-05T11:56:00.770 回答
0

Android 使用属性将正确的可绘制对象映射到 api 级别、应用程序主题、设备配置等。试试下面的代码行。

lastName.SetBackgroundResource(Android.Resource.Attribute.EditTextBackground);
于 2013-04-04T18:29:16.347 回答