我一直在研究如何在Android应用中突出显示焦点编辑文本表单字段。
当我关注我的电子邮件字段时,没有视觉反馈。
我应该提供什么样的视觉反馈?是否有用户期望的标准?
我在考虑一些背景颜色突出显示或某些字段边框颜色。
有任何方法可以达到这个目的吗?
我的布局是:
<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 /文件夹中,我在包含<item android:drawable="@drawable/textfield_selected" android:state_enabled="true" android:state_focused="true" />
的drawable /文件夹中添加了一个edit_text.xml文件
我在我的字段中添加了属性android:background =“@ drawable / edit_text”。但现在这个领域太小了。使用此样式的图像会覆盖我现有的样式。没有图像有没有办法做到这一点?
答案 0 :(得分:2)
您必须在drawable文件夹中创建一个选择器。这个选择器将具有editText的不同状态(有焦点或没有焦点)。
<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中,你可以把这个选择器作为背景,它应该可以工作。