Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Monodroid:更改edittext样式(红色边框),然后返回默认样式_Android_Xamarin.android - Fatal编程技术网

Android Monodroid:更改edittext样式(红色边框),然后返回默认样式

Android Monodroid:更改edittext样式(红色边框),然后返回默认样式,android,xamarin.android,Android,Xamarin.android,在某些情况下(使用shape),我将红色边框放在edittext上,之后我想回到默认的android风格edittext 我试着这样做: EditText lastName = FindViewById<EditText>(Resource.Id.lastName); lastName.SetBackgroundResource(Android.Resource.Drawable.EditBoxBackgroundNormal); EditText lastName=findvie

在某些情况下(使用shape),我将红色边框放在edittext上,之后我想回到默认的android风格edittext

我试着这样做:

EditText lastName = FindViewById<EditText>(Resource.Id.lastName);
lastName.SetBackgroundResource(Android.Resource.Drawable.EditBoxBackgroundNormal);
EditText lastName=findviewbyd(Resource.Id.lastName);
SetBackgroundResource(Android.Resource.Drawable.EditBoxBackgroundNormal);
它显示长长的白色条,而不是edittext的默认样式(黑色背景和灰线)


如何获得此默认样式的edittext?

Android使用属性将正确的绘图映射到api级别、应用程序主题、设备配置等。请尝试以下代码行

lastName.SetBackgroundResource(Android.Resource.Attribute.EditTextBackground);
如何设置“错误”标志?与其移除背景
Drawable
,我只需将其设置为:

myEditText.SetCompoundDrawablesWithIntrinsicBounds(0 , 0, Resource.Drawable.MyErrorIcon, 0);
其中
myEditText
EditText
Resource.Drawable的实例。MyErrorIcon
是要显示的图标的
Drawable

您可以通过以下操作将其删除:

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

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

的背景资源,我尝试了您的代码,但它给出了一个未处理的异常:
Android.Content.Res.Resources+NotFoundException:Resource ID#0x1010352
这不可能保存EditText的旧背景单机器人?(android java:
activity.findViewById(id.getBackground();
)是的,这会很好。我想做的是,当值不好时,将edittext的边框设置为红色,当edittext值正常时,返回默认样式。有一种方法可以做到这一点吗?请编辑您的问题,以反映这一点,而不是在评论中。链接tiny.cc已断开并从您的帖子中删除。请在不使用URL缩写的情况下重新更新它,但要使用真正的链接。