【问题标题】:EditText changes background color after focusEditText 在焦点后更改背景颜色
【发布时间】:2017-11-13 13:43:02
【问题描述】:

我在CardView 内有一个EditText,它在获得焦点后会改变其背景颜色,就像在其中写入文本一样。我希望它像第二张照片一样。

聚焦前:

聚焦后:

代码:

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:foreground="?android:attr/selectableItemBackground">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:drawableLeft="@drawable/ic_search"
        android:drawablePadding="16dp"
        android:drawableStart="@drawable/ic_search"
        android:hint="@string/search_library"
        android:imeOptions="actionSearch"
        android:inputType="textCapSentences"
        android:padding="16dp"
        android:textSize="16sp"/>
</android.support.v7.widget.CardView>

【问题讨论】:

  • 设置编辑文本背景为android:background="@null"
  • @ADM 不起作用。
  • 为什么在卡片视图中使用焦点属性?也删除这些属性和前景。
  • 尝试删除前景属性。
  • @ADM 删除前台工作。我用它来获得关于 CardView 的涟漪反馈,但使用 EditText 没有用。谢谢!

标签: android xml android-edittext


【解决方案1】:

使用selector 在edittext 聚焦时更改背景。

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:drawable="@drawable/edittext_focused" />
    <item android:state_focused="false" android:drawable="@drawable/edittext_notfocused" />
</selector>

然后在edittext_focused.xml 文件中添加您的偏好。

【讨论】:

    【解决方案2】:

    请移除前景属性。

    【讨论】:

      猜你喜欢
      • 2015-02-12
      • 2014-11-08
      • 2018-04-14
      • 2013-09-12
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      相关资源
      最近更新 更多