问题描述
我一直在研究如何在Android应用程序中突出显示重点突出的编辑文本表单字段.
I have been looking on how to highlight a focused edit text form field in an Android app.
当我关注电子邮件字段时,没有视觉反馈.
When I focus my email field, there is no visual feedback.
我应该提供什么样的视觉反馈?用户期望的标准吗?
What sort of visual feedback should I provide ? Is there a standard on what the user expects ?
我在想一些背景颜色突出显示或某些字段边框颜色.
I was thinking of some background color highlight or some field border color.
任何实现这一目标的方法吗?
Any way to achieve this ?
我的布局是:
<EditText
android:id="@+id/login_email_edittext"
style="@style/editext_graybg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_username"
android:drawableStart="@drawable/ic_username"
android:hint="@string/login_email_hint" >
<requestFocus />
</EditText>
样式:
<style name="editext_graybg" parent="android:Widget.EditText">
<item name="android:background">@drawable/editext_bg_gray</item>
<item name="android:drawablePadding">@dimen/pad_10dp</item>
<item name="android:ems">10</item>
<item name="android:inputType">textEmailAddress</item>
<item name="android:paddingLeft">@dimen/pad_10dp</item>
<item name="android:paddingRight">@dimen/pad_10dp</item>
<item name="android:textColor">@color/black</item>
<item name="android:textSize">@dimen/txt_18sp</item>
</style>
我尝试了以下解决方案,但由于它会减小我样式优美的字段的大小,因此并不令人满意:我将textfield_selected.9.png图像文件添加到了drawable/文件夹中,并将一个edit_text.xml文件添加到了drawable/文件夹中,其中包含<item android:drawable="@drawable/textfield_selected" android:state_enabled="true" android:state_focused="true" />
然后将属性android:background ="@ drawable/edit_text"添加到我的字段中.但是现在领域太小了.使用图像进行这种样式设置会覆盖我现有的样式.没有图像有没有办法做到这一点?
I tried the following solution but it is not satisfactory as it reduces the size of my beautifully styled field:I added textfield_selected.9.png image file into the drawable/ folder, I added a edit_text.xml file in the drawable/ folder containing a <item android:drawable="@drawable/textfield_selected" android:state_enabled="true" android:state_focused="true" />
and I added the attribute android:background="@drawable/edit_text" to my field. But the field is too small now. Using an image for this styling overwrites my existing styling. Is there any way to do this without an image ?
推荐答案
您必须在可绘制文件夹中创建一个选择器.该选择器将具有editText的不同状态(是否具有焦点).
You must create a selector inside your drawable folder. This selector will have the different states of the editText (with focus or not i.e).
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="@android:drawable/edittext_pressed"
/>
<item
android:state_focused="true"
android:drawable="@drawable/edittext_focused"
/>
<item
android:drawable="@android:drawable/edittext_normal"
/>
然后,在您的editText中,您可以将此选择器作为背景放置,它应该可以工作.
After that in your editText you can put as background this selector and it should work.
这篇关于突出显示重点突出的编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!