【问题标题】:Move drawable right to left on EditText focus在 EditText 焦点上从右向左移动 drawable
【发布时间】:2015-08-14 17:22:55
【问题描述】:

当专注于 EditText 时,我需要将我的图标从 EditText 的右侧移动到左侧(动画)。我还需要放置另一个图标来代替可绘制的权利。

这是我目前的 XML 布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    tools:context="com.example.SearchActivity">

    <EditText
        android:id="@+id/barSearch"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="0dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/search_bar"
        android:drawableRight="@drawable/ic_search_white"
        android:drawingCacheQuality="high"
        android:ems="10"
        android:gravity="start"
        android:lines="1"
        android:maxLines="1"
        android:paddingBottom="10dp"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:paddingTop="10dp"
        android:singleLine="true"
        android:focusable="true" android:focusableInTouchMode="true"
        android:imeOptions="actionSearch"
        android:textColor="@color/white"
        android:textStyle="bold" />

另外,当我开始活动时,EditText 失去焦点,如果我点击它,它就会获得焦点,但是当我点击其他按钮或点击后退按钮时,我想失去焦点。如果我点击后退按钮,键盘消失,但 EditText 保持焦点。

有谁知道实现这一目标的正确方法是什么。

【问题讨论】:

  • 为了更新编辑文本上的图标,我建议使用 setCompoundDrawablesWithIntrinsicBounds() 方法。但变化立即发生。

标签: android android-layout


【解决方案1】:

试试这个.....

// Set drawables for left, top, right, and bottom - send 0 for nothing

editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0);

【讨论】:

    猜你喜欢
    • 2017-12-23
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 1970-01-01
    相关资源
    最近更新 更多