@@ -156,33 +156,36 @@ public EasyIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
156156 */
157157 private void init (Context context , AttributeSet attrs , int defStyleAttr ) {
158158 TypedArray typedArray = context .obtainStyledAttributes (attrs , R .styleable .EasyIndicator , defStyleAttr , 0 );
159- if (typedArray != null ) {
160- indicatorWidth = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_width , indicatorWidth );
161- indicatorHeight = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_height , indicatorHeight );
162- indicatorLineShow = typedArray .getBoolean (R .styleable .EasyIndicator_indicator_line_show , indicatorLineShow );
163- indicatorLineWidth = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_line_width , indicatorLineWidth );
164- indicatorLineHeight = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_line_height , indicatorLineHeight );
165- indicatorLineColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_line_color , ThemeUtils .getMainThemeColor (getContext ()));
166- indicatorLineDrawable = ResUtils .getDrawableAttrRes (context , typedArray , R .styleable .EasyIndicator_indicator_line_res );
167- indicatorBottomLineHeight = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_bottom_line_height , indicatorBottomLineHeight );
168- indicatorBottomLineColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_bottom_line_color , ThemeUtils .resolveColor (getContext (), R .attr .xui_config_color_separator_dark ));
169- indicatorSelectedColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_selected_color , ThemeUtils .getMainThemeColor (getContext ()));
170- indicatorNormalColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_normal_color , ResUtils .getColor (R .color .xui_config_color_black ));
171- indicatorTextSize = getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_textSize , (int ) indicatorTextSize );
172- indicatorVerticalLineWidth = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_vertical_line_w , indicatorVerticalLineWidth );
173- indicatorVerticalLineColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_vertical_line_color , ThemeUtils .resolveColor (getContext (), R .attr .xui_config_color_separator_dark ));
174- indicatorVerticalLineHeight = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_vertical_line_h , indicatorVerticalLineHeight );
175- indicatorSelectTextSize = getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_select_textSize , 14 );
176- // 指引器不能超过屏幕的宽度
177- indicatorWidth = Math .min (indicatorWidth , screenWidth );
178- if (indicatorWidth == 0 ) {
179- indicatorWidth = LayoutParams .MATCH_PARENT ;
180- }
181- typedArray .recycle ();
159+ indicatorWidth = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_width , indicatorWidth );
160+ indicatorHeight = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_height , indicatorHeight );
161+ Drawable indicatorBgDrawable = ResUtils .getDrawableAttrRes (context , typedArray , R .styleable .EasyIndicator_indicator_background );
162+ indicatorLineShow = typedArray .getBoolean (R .styleable .EasyIndicator_indicator_line_show , indicatorLineShow );
163+ indicatorLineWidth = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_line_width , indicatorLineWidth );
164+ indicatorLineHeight = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_line_height , indicatorLineHeight );
165+ indicatorLineColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_line_color , ThemeUtils .getMainThemeColor (getContext ()));
166+ indicatorLineDrawable = ResUtils .getDrawableAttrRes (context , typedArray , R .styleable .EasyIndicator_indicator_line_res );
167+ indicatorBottomLineHeight = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_bottom_line_height , indicatorBottomLineHeight );
168+ indicatorBottomLineColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_bottom_line_color , ThemeUtils .resolveColor (getContext (), R .attr .xui_config_color_separator_dark ));
169+ indicatorSelectedColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_selected_color , ThemeUtils .getMainThemeColor (getContext ()));
170+ indicatorNormalColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_normal_color , ResUtils .getColor (R .color .xui_config_color_black ));
171+ indicatorTextSize = getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_textSize , (int ) indicatorTextSize );
172+ indicatorVerticalLineWidth = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_vertical_line_w , indicatorVerticalLineWidth );
173+ indicatorVerticalLineColor = typedArray .getColor (R .styleable .EasyIndicator_indicator_vertical_line_color , ThemeUtils .resolveColor (getContext (), R .attr .xui_config_color_separator_dark ));
174+ indicatorVerticalLineHeight = (int ) getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_vertical_line_h , indicatorVerticalLineHeight );
175+ indicatorSelectTextSize = getDimensionPixelSize (typedArray , R .styleable .EasyIndicator_indicator_select_textSize , 14 );
176+ typedArray .recycle ();
177+ // 指引器不能超过屏幕的宽度
178+ indicatorWidth = Math .min (indicatorWidth , screenWidth );
179+ if (indicatorWidth == 0 ) {
180+ indicatorWidth = LayoutParams .MATCH_PARENT ;
182181 }
183182 tabContent = new LinearLayout (getContext ());
184183 LayoutParams params = new LayoutParams (indicatorWidth , LayoutParams .WRAP_CONTENT );
185- tabContent .setBackgroundColor (Color .WHITE );
184+ if (indicatorBgDrawable != null ) {
185+ tabContent .setBackground (indicatorBgDrawable );
186+ } else {
187+ tabContent .setBackgroundColor (Color .WHITE );
188+ }
186189 params .gravity = Gravity .CENTER ;
187190 tabContent .setLayoutParams (params );
188191 tabContent .setGravity (Gravity .CENTER );
@@ -424,7 +427,9 @@ private void initScreenWidth() {
424427 DisplayMetrics dm = getResources ().getDisplayMetrics ();
425428 screenHeight = dm .heightPixels ;
426429 screenWidth = dm .widthPixels ;
427-
428430 }
429431
432+ public LinearLayout getTabContent () {
433+ return tabContent ;
434+ }
430435}
0 commit comments