删除EditText的焦点边框

如何在聚焦EditText视图时删除出现的边框?

我需要它,因为这个视图在屏幕上没有空间,但没有边界就足够了。 在模拟器上运行时,会出现一个橙色边框,在设备上显示一个蓝色边框。

您是否尝试过将EditText的背景设置为透明颜色?

 <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/hello" android:background="#00000000" /> 
 <EditText android:id="@+id/edittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background_normal" /> 

有可能的。 不过我不会推荐它,因为用户习惯于某些隐喻,你不应该改变一般的用户体验。

您可以将不同的风格应用于您的观点。 在你的情况下,它听起来像你想要一个EditText视图元素看起来像一个TextView元素。 在这种情况下,您将不得不为EditText指定其他背景,具体取决于View元素的状态。

在你想要的layout.xml中,为你的EditText分配一个背景:

 <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/hello" android:background="@drawable/custom" /> 

然后,在您的可绘制文件夹中创buildcustom.xml并添加以下内容:

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/textfield_default" /> <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_disabled" /> <item android:state_pressed="true" android:drawable="@drawable/textfield_default" /> <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_default" /> <item android:state_enabled="true" android:drawable="@drawable/textfield_default" /> <item android:state_focused="true" android:drawable="@drawable/textfield_disabled" /> <item android:drawable="@drawable/textfield_disabled" /> </selector> 

这些是您的EditText视图元素的可能状态。 通常情况下,您可以使用@android:drawable/textfield_default直接访问Android平台的可@android:drawable/textfield_default ,但在这种情况下,textfield可绘制对象是私有的,因此您必须将它们复制到您自己的可绘制文件夹中。 原始资源可以在您的SDK安装文件夹中的ANDROID_HOME\platforms\android-(API LEVEL)\data\res\drawable-(*dpi)\

一旦你完成了,你最终会看到一个EditText,看起来像一个TextView,但完全没有这些边界。 您在模拟器中看到的那些橙色边框是默认的Android可绘制的。 蓝色的是供应商特定的(可能是三星)。

希望有所帮助,而不是混淆那么多。

这是最快的解决scheme:

 <EditText android:id="@+id/edittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#00000000" />