久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

無法在 TextInputLayout 內的 EditText 中使用 drawable

Unable to use drawable in EditText inside TextInputLayout(無法在 TextInputLayout 內的 EditText 中使用 drawable)
本文介紹了無法在 TextInputLayout 內的 EditText 中使用 drawable的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我最近將 Android 設計庫從 24.2.1 升級到了 25.0.0.在此之后 EditText 中的drawableX"功能不起作用.

I recently upgraded Android Design library from 24.2.1 to 25.0.0. After this the "drawableX" feature in EditText doesn't work.

編輯 01.11:我了解到,如果您使用 android:drawableStart 而不是 android:drawableLeft,則在 xml 中設置 drawable 有效.但是以編程方式設置設置drawables不起作用.我用它來制作一個清除"按鈕來清空 EditText.但是這個功能現在被打破了.如果這是來自 Google 的故意或錯誤,我將不勝感激任何解決方法或知識!

EDIT 01.11: I learned that setting drawable in xml works if you use android:drawableStart instead of android:drawableLeft. But setting setting drawables programatically does not work. I use this to make a "Clear"-button to empty the EditText. But this feature is broken now. I would appreciate any work-arounds or knowledge about if this is intentional from Google or a bug!

我的可清除編輯文本代碼以前有效但現在無效:

My code for Clearable edit-text that worked before but doesn't now:

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) {
                setText("");
                return false; // true will fail on emulator running 2.1 and physical keyboard / scroll wheel
            }
        }
    }
    return false;
}

@Override
public void setOnFocusChangeListener(OnFocusChangeListener l) {
    childFocusListener = l;
}

@Override
public void onFocusChange(View v, boolean hasFocus) {
    setClearIconVisible(hasFocus && getText().length() > 0);

    if (childFocusListener!=null){
        childFocusListener.onFocusChange(v, hasFocus);
    }
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count){
    super.onTextChanged(s, start, before, count);
    setClearIconVisible(isFocused() && s.length() > 0);
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} // not interesting

@Override
public void afterTextChanged(Editable s) {} //  // not interesting

private void setup() {
    if(isInEditMode()){
        return;
    }

    resIcon = getResources().getDrawable(R.drawable.ic_clear, null);
    resIcon.setBounds(0, 0, resIcon.getIntrinsicWidth(), resIcon.getIntrinsicHeight());

    setClearIconVisible(false);

    super.setOnTouchListener(this);
    super.setOnFocusChangeListener(this);
    addTextChangedListener(this);
}

private void setClearIconVisible(final boolean visible){
    final Drawable icon = visible ? resIcon : null;
    setCompoundDrawables(getCompoundDrawables()[0],
            getCompoundDrawables()[1], icon, getCompoundDrawables()[3]);
}

推薦答案

根據 Ahmed Ashraf G 的回答,我找到了解決方案.更改以下代碼:

Based on the answer by Ahmed Ashraf G, I was able to find the solution. Changing the following code:

setCompoundDrawables(getCompoundDrawables()[0],
        getCompoundDrawables()[1], icon, getCompoundDrawables()[3]);

到:

setCompoundDrawablesRelative(getCompoundDrawablesRelative()[0],
            getCompoundDrawablesRelative()[1], icon, getCompoundDrawablesRelative()[3]);

從 StackOverflow 上的其他地方(文檔沒有提到這一點),xxxCompoundDrawablesXxx 和 xxxCompundDrawablesRelativeXxx 之間的區別在于相對版本考慮了 RTL 語言,即它們與使用 drawableStart 而不是 drawableLeft 相同.

From other places on StackOverflow (the documentation does NOT mention this) the difference between xxxCompoundDrawablesXxx and xxxCompundDrawablesRelativeXxx is that the relative versions take into account RTL-languages, ie they are the same as using drawableStart instead of drawableLeft.

因此,總而言之,Google 已經破壞了 TextInputLayout 內 EditText 的所有不是 RTL 方法的方法.由于新方法是在 API 級別 17 中添加的,我認為這是主要錯誤,可能會在未來的更新中修復

So in conclusion, Google has broken all methods that are not RTL-methods for EditText inside TextInputLayout. Since the new methods are added in API level 17 I see this as major bug, that will probably be fixed in future updates

這篇關于無法在 TextInputLayout 內的 EditText 中使用 drawable的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 一区二区三区在线电影 | 久久综合久久综合久久 | www国产成人免费观看视频,深夜成人网 | 欧美日韩视频在线第一区 | 天天综合网天天综合 | 国产人成精品一区二区三 | 伊人免费视频二 | 国产一二区视频 | 91在线资源 | 亚洲精品久久久久中文字幕欢迎你 | av色噜噜 | 欧美色综合网 | 久久伊人操 | 亚洲精品视频一区二区三区 | 一级片在线免费播放 | 羞羞视频一区二区 | 97人澡人人添人人爽欧美 | 国内精品在线视频 | 欧美一区二区激情三区 | 午夜伊人 | 亚洲精品一区二区网址 | 国产精品久久久久久模特 | 亚洲高清网| 精品婷婷| 99re视频这里只有精品 | 韩日精品视频 | 天天躁日日躁aaaa视频 | 久久久久久久久久一区二区 | 久久久精品国产 | 久久久www成人免费无遮挡大片 | 久久久久久久久91 | 少妇一级淫片免费放播放 | 亚洲成人a v | 亚洲精品久久久久久一区二区 | 久久伊人青青草 | 国产欧美精品在线观看 | 毛片综合| 亚洲欧美一区二区三区情侣bbw | 国产精品免费一区二区三区四区 | 成人欧美一区二区三区黑人孕妇 | 成人网视频 |