14
14
import android .util .TypedValue ;
15
15
import android .view .Gravity ;
16
16
import android .view .View ;
17
+ import android .view .ViewGroup ;
17
18
import android .widget .EditText ;
18
19
import android .widget .ImageView ;
19
20
import android .widget .LinearLayout ;
@@ -413,29 +414,36 @@ private void initAttrs(Context context, AttributeSet attrs) {
413
414
//设置内容对齐方式
414
415
setGravity (Gravity .CENTER_VERTICAL );
415
416
//添加视图(ImageView + TextView +TextView + EditText + ImageView + ImageView)
417
+
416
418
leftImageView = new ImageView (context );
417
419
leftImageView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
418
420
addView (leftImageView );
421
+
419
422
leftTextView = new TextView (context );
420
423
leftTextView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
421
424
addView (leftTextView );
425
+
422
426
centerTextView = new TextView (context );
423
427
centerTextView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
424
428
addView (centerTextView );
429
+
425
430
rightTextView = new TextView (context );
426
431
rightTextView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
427
432
addView (rightTextView );
433
+
428
434
// 文本控件
429
435
editView = new EditText (context );
430
436
editView .setLayoutParams (new LayoutParams (LayoutParams .MATCH_PARENT , LayoutParams .MATCH_PARENT ));
431
437
addView (editView );
432
-
438
+ // 图标
433
439
centerImageView = new ImageView (context );
434
440
centerImageView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
435
441
addView (centerImageView );
442
+
436
443
rightImageView = new ImageView (context );
437
444
rightImageView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
438
445
addView (rightImageView );
446
+
439
447
//左边图标
440
448
leftImageView .setImageResource (leftImageSrc );
441
449
leftImageView .setBackgroundResource (leftImageBackground );
@@ -469,6 +477,7 @@ private void initAttrs(Context context, AttributeSet attrs) {
469
477
if (!TextUtils .isEmpty (editText )) {
470
478
editView .setText (editText );
471
479
}
480
+
472
481
editView .setFilters (new InputFilter []{new InputFilter .LengthFilter (editMaxLength )});
473
482
editView .setTextColor (editTextColor );
474
483
editView .setFocusable (editFocusable );
@@ -479,6 +488,7 @@ private void initAttrs(Context context, AttributeSet attrs) {
479
488
if (editMaxLines != 0 ) {
480
489
editView .setMaxLines (editMaxLines );
481
490
}
491
+
482
492
editView .setEllipsize (truncateAts [editEllipsize ]);
483
493
editView .setInputType (inputTypes [editInputType ]);
484
494
editView .setText (editText );
@@ -488,18 +498,21 @@ private void initAttrs(Context context, AttributeSet attrs) {
488
498
if (!TextUtils .isEmpty (editDigits )) {
489
499
editView .setKeyListener (DigitsKeyListener .getInstance (editDigits ));
490
500
}
501
+
491
502
//中间图标
492
503
setMarginPaddingWeight (centerImageView , centerImageMargin , centerImageMarginLeft , centerImageMarginTop , centerImageMarginRight , centerImageMarginBottom , centerImagePadding , centerImagePaddingLeft , centerImagePaddingTop , centerImagePaddingRight , centerImagePaddingBottom , -1 );
493
504
centerImageView .setImageResource (centerImageSrc );
494
505
centerImageView .setBackgroundResource (centerImageBackground );
495
506
centerImageView .setScaleType (scaleTypes [centerImageScaleType ]);
496
507
setParams (centerImageView , centerImageWidth , centerImageHeight );
508
+
497
509
//右边图标
498
510
setMarginPaddingWeight (rightImageView , rightImageMargin , rightImageMarginLeft , rightImageMarginTop , rightImageMarginRight , rightImageMarginBottom , rightImagePadding , rightImagePaddingLeft , rightImagePaddingTop , rightImagePaddingRight , rightImagePaddingBottom , -1 );
499
511
rightImageView .setImageResource (rightImageSrc );
500
512
rightImageView .setBackgroundResource (rightImageBackground );
501
513
rightImageView .setScaleType (scaleTypes [rightImageScaleType ]);
502
514
setParams (rightImageView , rightImageWidth , rightImageHeight );
515
+
503
516
//全属性
504
517
setAllTextSize ();
505
518
setAllTextColor ();
0 commit comments