【问题标题】:How to change background image for focused state of edittext如何为edittext的焦点状态更改背景图像
【发布时间】:2012-07-12 23:38:12
【问题描述】:

我知道我的问题的标题听起来像是一个已经回答的问题。 但是,我的问题有点不同,我找不到解决方案

在我的应用程序中,我有一个带有两个 EditText 的登录屏幕。我使用 Theme.Holo.Light 的修改版本。

EditText 如下所示:

如您所见,文本下方有不同颜色的边框,具体取决于 EditText 的状态。

所以这是我的问题:谁能告诉我如何更改这些边框的颜色??

我希望任何人都可以帮助我!提前致谢!

编辑:

不幸的是,我遇到了另一个问题:

我能够使用 dtmilano 的解决方案更改背景图像。 但是,添加 StateListDrawable 删除了 EditView 的填充。如果我添加文本,光标位于最左边的位置,而不是像以前那样在描绘的边框内。 到目前为止,我无法引入这个填充,例如与 android:paddingLeft.

谁能告诉我哪个属性被这个选择器覆盖了

    <?xml version="1.0" encoding="utf-8"?>
    <selector 
        xmlns:android="http://schemas.android.com/apk/res/android"  
        >
        <item 
            android:state_pressed="true"
            android:drawable="@drawable/edittext_pressed" 
            /> <!-- pressed -->    
        <item 
            android:state_focused="true"
            android:drawable="@drawable/edittext_focused"
            /> <!-- focused -->    
        <item 
            android:drawable="@drawable/edittext_default" 
            /> <!-- default -->
    </selector>

还有一个像这样的 EditText:

    <EditText
        android:id="@+id/loginEmail"
        android:background="@drawable/edittext_modified_states"
        android:inputType="textEmailAddress"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

【问题讨论】:

    标签: android colors themes android-edittext border


    【解决方案1】:

    您应该在主题中使用StateListDrawable 作为 EditText 的背景,以便处理不同的状态。

    【讨论】:

    • 不幸的是,我遇到了另一个问题并编辑了我的问题。你能帮帮我吗,dtmilano?
    • 使用9 patches,这样您就可以指定内容的去向
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 2011-12-09
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多