相关疑难解决方法(0)

无法在TextInputLayout中的EditText中使用drawable

我最近将Android设计库从24.2.1升级到25.0.0.在此之后,EditText中的"drawableX"功能不起作用.

编辑01.11:我了解到如果你使用android:drawableStart而不是android:drawableLeft,在xml中设置drawable是有效的.但是以编程方式设置drawable不起作用.我使用它来制作一个"清除"按钮来清空EditText.但是这个功能现在已经破了.如果这是故意的谷歌或一个错误,我将不胜感激任何解决方法或知识!

我的可编辑文本的代码之前有效,但现在没有:

public class ClearableErrorTextInputEditText extends ErrorTextInputEditText implements View.OnFocusChangeListener, View.OnTouchListener, TextWatcher {

private Drawable resIcon;
private OnFocusChangeListener childFocusListener;

public ClearableErrorTextInputEditText(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setup();
}

public ClearableErrorTextInputEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
    setup();
}

public ClearableErrorTextInputEditText(Context context) {
    super(context);
    setup();
}

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        if (getCompoundDrawables()[2] != null) {
            final boolean tappedClose = event.getX() > (getWidth() - getPaddingRight() - resIcon.getIntrinsicWidth());
            if (tappedClose) …
Run Code Online (Sandbox Code Playgroud)

android android-edittext android-design-library android-textinputlayout

2
推荐指数
3
解决办法
2849
查看次数