【问题标题】:Highlighting a focused edit text突出显示焦点编辑文本
【发布时间】:2015-05-27 08:02:47
【问题描述】:

我一直在研究如何在 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/ 文件夹中,我在 drawable/ 文件夹中添加了一个 edit_text.xml 文件,其中包含 &lt;item android:drawable="@drawable/textfield_selected" android:state_enabled="true" android:state_focused="true" /&gt; 我将属性 android:background="@drawable/edit_text" 添加到我的字段中。但是现在这个领域太小了。使用此样式的图像会覆盖我现有的样式。没有图片有什么办法吗?

【问题讨论】:

标签: android css android-layout


【解决方案1】:

您必须在您的可绘制文件夹中创建一个选择器。此选择器将具有不同的 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 之后,你可以把这个选择器作为背景,它应该可以工作。

【讨论】:

  • 我接受你的回答,因为你写的是正确的。只是让你知道,我无法理解你的回答,它对我一点帮助也没有。经过几天的搜索和尝试,我现在自己解决了这个问题。但没有难过的感觉,无论如何我还是感谢你的尝试。
  • 谢谢,但你可以问我你不明白什么;)有时当你理解某些东西时,你认为它是可以自动解释的,但你没有说清楚。我想这发生在我身上。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-23
  • 2019-03-21
  • 2010-11-29
  • 1970-01-01
  • 2019-05-27
  • 2016-01-17
  • 1970-01-01
相关资源
最近更新 更多