|
8 | 8 | import android.graphics.drawable.GradientDrawable;
|
9 | 9 | import android.os.Build;
|
10 | 10 | import android.support.annotation.Nullable;
|
| 11 | +import android.text.InputFilter; |
11 | 12 | import android.text.TextUtils;
|
12 | 13 | import android.text.method.DigitsKeyListener;
|
13 | 14 | import android.util.AttributeSet;
|
@@ -142,6 +143,7 @@ public class TextGroupView extends LinearLayout {
|
142 | 143 | private int editBackground;
|
143 | 144 | private boolean editSingleLine;
|
144 | 145 | private int editMaxLines;
|
| 146 | + private int editMaxLength; |
145 | 147 | private String editDigits;
|
146 | 148 | private int editEllipsize;
|
147 | 149 | private int editInputType;
|
@@ -350,11 +352,12 @@ private void initAttrs(Context context, AttributeSet attrs) {
|
350 | 352 | //右边输入
|
351 | 353 | editWidth = typedArray.getLayoutDimension(R.styleable.TextGroupView_edit_width, LayoutParams.WRAP_CONTENT);
|
352 | 354 | editHeight = typedArray.getLayoutDimension(R.styleable.TextGroupView_edit_height, LayoutParams.WRAP_CONTENT);
|
353 |
| - editHintTextColor = typedArray.getColor(R.styleable.TextGroupView_edit_hintTextColor, 0); |
| 355 | + editHintTextColor = typedArray.getColor(R.styleable.TextGroupView_edit_hintTextColor, Color.parseColor("#B9B9B9")); |
354 | 356 | editFocusable = typedArray.getBoolean(R.styleable.TextGroupView_edit_focusable, true);
|
355 | 357 | editHintText = typedArray.getString(R.styleable.TextGroupView_edit_hintText);
|
356 | 358 | editBackground = typedArray.getResourceId(R.styleable.TextGroupView_edit_background, 0);
|
357 | 359 | editMaxLines = typedArray.getInt(R.styleable.TextGroupView_edit_maxLines, 0);
|
| 360 | + editMaxLength = typedArray.getInt(R.styleable.TextGroupView_edit_maxLength, Integer.MAX_VALUE); |
358 | 361 | editDigits = typedArray.getString(R.styleable.TextGroupView_edit_digits);
|
359 | 362 | editEllipsize = typedArray.getInt(R.styleable.TextGroupView_edit_ellipsize, 0);
|
360 | 363 | editSingleLine = typedArray.getBoolean(R.styleable.TextGroupView_edit_singleLine, false);
|
@@ -465,6 +468,7 @@ private void initAttrs(Context context, AttributeSet attrs) {
|
465 | 468 | if (!TextUtils.isEmpty(editText)) {
|
466 | 469 | editView.setText(editText);
|
467 | 470 | }
|
| 471 | + editView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(editMaxLength)}); |
468 | 472 | editView.setTextColor(editTextColor);
|
469 | 473 | editView.setFocusable(editFocusable);
|
470 | 474 | editView.setHintTextColor(editHintTextColor);
|
@@ -1512,6 +1516,15 @@ public void setEditMaxLines(int editMaxLines) {
|
1512 | 1516 | editView.setMaxLines(editMaxLines);
|
1513 | 1517 | }
|
1514 | 1518 |
|
| 1519 | + public int getEditMaxLength() { |
| 1520 | + return editMaxLength; |
| 1521 | + } |
| 1522 | + |
| 1523 | + public void setEditMaxLength(int editMaxLength) { |
| 1524 | + this.editMaxLength = editMaxLength; |
| 1525 | + editView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(editMaxLength)}); |
| 1526 | + } |
| 1527 | + |
1515 | 1528 | public String getEditDigits() {
|
1516 | 1529 | return editDigits;
|
1517 | 1530 | }
|
|
0 commit comments