删除EditText的焦点边框
如何删除聚焦 EditText 视图时出现的边框?
我需要它,因为这个视图在屏幕上的空间很小,但没有边框就足够了。在模拟器上运行时,会出现橙色边框,在设备上运行时会出现蓝色边框。
How can I remove the border with appears when focusing an EditText View?
I need it cause this view has little space in the screen, but without the border it's enough. When running on Emulator an orange border appears, on Device a blue one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否尝试过将
EditText
的背景设置为透明颜色?Have you tried setting the background of the
EditText
to a transparent colour?这是可能的。但是我不会推荐它,因为用户已经习惯了某些隐喻,并且您不应该改变一般的用户体验。
您可以将不同的样式应用于您的视图。在您的情况下,听起来您想要一个看起来像 TextView 元素的 EditText View 元素。在这种情况下,您必须根据 View 元素的状态为 EditText 指定其他背景。
在所需的layout.xml 中,为EditText 指定背景:
然后在drawable 文件夹中创建custom.xml 并添加以下内容:
这些是EditText 视图元素的可能状态。通常,您可以使用
@android:drawable/textfield_default
直接访问 Android 平台可绘制对象,但在这种情况下,文本字段可绘制对象是私有的,因此您必须将它们复制到您自己的可绘制对象文件夹中。原始资源可以在您的 SDK 安装文件夹中找到:ANDROID_HOME\platforms\android-(API LEVEL)\data\res\drawable-(*dpi)\
。完成后,您最终会得到一个看起来像 TextView 但完全没有这些边框的 EditText。您在模拟器中看到的橙色边框是默认的 Android 可绘制对象。蓝色的是特定于供应商的(可能是三星)。
希望这对您有所帮助,并且不会造成太多困惑。
It is possible. However I would not recommend it because users are used to certain metaphors and you should not change the general UX.
You can apply different styles to your views. In your case it sounds like you want an EditText View element which looks like a TextView element. In this case you would have to specify other backgrounds for the EditText depending on the state of the View element.
In your desired layout.xml you assign a background to your EditText:
Then you create the custom.xml in your drawable folder and add the following:
Those are the possible states of your EditText View element. Normally you can access Android platform drawables directly by using
@android:drawable/textfield_default
, but in this case the textfield drawables are private so you have to copy them into your own drawable folder. The original resources can be found in your SDK installation folder atANDROID_HOME\platforms\android-(API LEVEL)\data\res\drawable-(*dpi)\
.Once you are done you end up with an EditText which looks like a TextView but completely without those borders. Those orange borders you saw in the emulator are the default Android drawables. The blue ones are vendor specific (possibly Samsung).
Hope that helped and didn't confuse that much.
这是最快的解决方案:
This is the fastest solution:
您可以将背景颜色保持为透明,以删除焦点上的 EditText 边框。
方法一
You can keep the background color as transparent to remove the EditText border on focus.
Method 1