diff --git a/library/src/main/java/com/lt/library/base/BaseViewHolder.java b/library/src/main/java/com/lt/library/base/BaseViewHolder.java index e23eb72..11f0f37 100644 --- a/library/src/main/java/com/lt/library/base/BaseViewHolder.java +++ b/library/src/main/java/com/lt/library/base/BaseViewHolder.java @@ -1,17 +1,20 @@ package com.lt.library.base; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; +import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.util.SparseArray; import android.view.View; import android.widget.ImageView; import android.widget.TextView; +import com.lt.library.util.context.ContextUtil; + import java.util.Objects; /** @@ -63,9 +66,14 @@ public void setTextSize(int viewId, float size) { view.setTextSize(size); }//设置文本大小 - public void setTextColor(int viewId, @ColorInt int colorInt) { + public void setTextColor(int viewId, @ColorRes int resId) { + TextView view = findViewById(viewId); + view.setTextColor(ContextCompat.getColor(ContextUtil.getInstance().getContext(), resId)); + }//设置文本颜色 + + public void setTextColorStateList(int viewId, @ColorRes int resId) { TextView view = findViewById(viewId); - view.setTextColor(colorInt); + view.setTextColor(ContextCompat.getColorStateList(ContextUtil.getInstance().getContext(), resId)); }//设置文本颜色 public void setImageDrawable(int viewId, @Nullable Drawable drawable) { @@ -88,9 +96,9 @@ public void setBackgroundResource(int viewId, @DrawableRes int resId) { view.setBackgroundResource(resId); }//设置背景资源 - public void setBackgroundColor(int viewId, @ColorInt int colorInt) { + public void setBackgroundColor(int viewId, @ColorRes int resId) { View view = findViewById(viewId); - view.setBackgroundColor(colorInt); + view.setBackgroundColor(ContextCompat.getColor(ContextUtil.getInstance().getContext(), resId)); }//设置背景颜色 public void setVisibility(int viewId, int visibility) { diff --git a/library/src/main/java/com/lt/library/util/EdtLinkBtnUtil.java b/library/src/main/java/com/lt/library/util/EdtLinkBtnUtil.java new file mode 100644 index 0000000..9c1273b --- /dev/null +++ b/library/src/main/java/com/lt/library/util/EdtLinkBtnUtil.java @@ -0,0 +1,79 @@ +package com.lt.library.util; + +import android.text.Editable; +import android.text.TextWatcher; +import android.util.ArrayMap; +import android.widget.Button; +import android.widget.EditText; + +import java.util.Map; + +public class EdtLinkBtnUtil implements TextWatcher { + private ArrayMap mEditTextMap; + private Button mButton; + + private EdtLinkBtnUtil() { + mEditTextMap = new ArrayMap<>(); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + boolean isEnable = false; + for (Map.Entry entry : mEditTextMap.entrySet()) { + EditText edt = entry.getKey(); + Integer btnEnableLength = entry.getValue(); + if (edt.getText().length() < btnEnableLength) { + isEnable = false; + break; + } else { + isEnable = true; + } + } + mButton.setEnabled(isEnable); + } + + public void addEvent() { + for (Map.Entry entry : mEditTextMap.entrySet()) { + EditText editText = entry.getKey(); + editText.addTextChangedListener(this); + } + } + + public void delEvent() { + for (Map.Entry entry : mEditTextMap.entrySet()) { + EditText editText = entry.getKey(); + editText.removeTextChangedListener(this); + } + } + + public static class Builder { + private EdtLinkBtnUtil mEdtLinkBtnUtil; + + public Builder() { + mEdtLinkBtnUtil = new EdtLinkBtnUtil(); + } + + public Builder addEditText(EditText editText, int btnEnableLength) { + mEdtLinkBtnUtil.mEditTextMap.put(editText, btnEnableLength); + return this; + } + + public Builder setButton(Button button) { + mEdtLinkBtnUtil.mButton = button; + mEdtLinkBtnUtil.mButton.setEnabled(false); + return this; + } + + public EdtLinkBtnUtil build() { + return mEdtLinkBtnUtil; + } + } +}