Skip to content

Commit

Permalink
EasyIndicator新增indicator_background属性,自定义背景颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
xuexiangjys committed Feb 28, 2022
1 parent 539b138 commit 3fbbbe9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
6 changes: 4 additions & 2 deletions app/src/main/res/layout/fragment_easy_indicator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
app:indicator_background="@color/xui_config_color_transparent"
app:indicator_height="42dp"
app:indicator_line_height="5dp"
app:indicator_line_res="@drawable/shape_indicator_line"
app:indicator_line_show="true"
app:indicator_line_width="30dp"
app:indicator_selected_color="#FF6100"
app:indicator_textSize="14sp"
app:indicator_vertical_line_h="30dp"
app:indicator_vertical_line_w="1dp"
app:indicator_vertical_line_color="@color/xui_config_color_white"
app:indicator_vertical_line_h="20dp"
app:indicator_vertical_line_w="1.5dp"
app:indicator_width="300dp" />

<com.xuexiang.xui.widget.tabbar.EasyIndicator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,33 +156,36 @@ public EasyIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
*/
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.EasyIndicator, defStyleAttr, 0);
if (typedArray != null) {
indicatorWidth = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_width, indicatorWidth);
indicatorHeight = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_height, indicatorHeight);
indicatorLineShow = typedArray.getBoolean(R.styleable.EasyIndicator_indicator_line_show, indicatorLineShow);
indicatorLineWidth = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_line_width, indicatorLineWidth);
indicatorLineHeight = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_line_height, indicatorLineHeight);
indicatorLineColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_line_color, ThemeUtils.getMainThemeColor(getContext()));
indicatorLineDrawable = ResUtils.getDrawableAttrRes(context, typedArray, R.styleable.EasyIndicator_indicator_line_res);
indicatorBottomLineHeight = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_bottom_line_height, indicatorBottomLineHeight);
indicatorBottomLineColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_bottom_line_color, ThemeUtils.resolveColor(getContext(), R.attr.xui_config_color_separator_dark));
indicatorSelectedColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_selected_color, ThemeUtils.getMainThemeColor(getContext()));
indicatorNormalColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_normal_color, ResUtils.getColor(R.color.xui_config_color_black));
indicatorTextSize = getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_textSize, (int) indicatorTextSize);
indicatorVerticalLineWidth = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_vertical_line_w, indicatorVerticalLineWidth);
indicatorVerticalLineColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_vertical_line_color, ThemeUtils.resolveColor(getContext(), R.attr.xui_config_color_separator_dark));
indicatorVerticalLineHeight = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_vertical_line_h, indicatorVerticalLineHeight);
indicatorSelectTextSize = getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_select_textSize, 14);
// 指引器不能超过屏幕的宽度
indicatorWidth = Math.min(indicatorWidth, screenWidth);
if (indicatorWidth == 0) {
indicatorWidth = LayoutParams.MATCH_PARENT;
}
typedArray.recycle();
indicatorWidth = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_width, indicatorWidth);
indicatorHeight = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_height, indicatorHeight);
Drawable indicatorBgDrawable = ResUtils.getDrawableAttrRes(context, typedArray, R.styleable.EasyIndicator_indicator_background);
indicatorLineShow = typedArray.getBoolean(R.styleable.EasyIndicator_indicator_line_show, indicatorLineShow);
indicatorLineWidth = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_line_width, indicatorLineWidth);
indicatorLineHeight = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_line_height, indicatorLineHeight);
indicatorLineColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_line_color, ThemeUtils.getMainThemeColor(getContext()));
indicatorLineDrawable = ResUtils.getDrawableAttrRes(context, typedArray, R.styleable.EasyIndicator_indicator_line_res);
indicatorBottomLineHeight = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_bottom_line_height, indicatorBottomLineHeight);
indicatorBottomLineColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_bottom_line_color, ThemeUtils.resolveColor(getContext(), R.attr.xui_config_color_separator_dark));
indicatorSelectedColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_selected_color, ThemeUtils.getMainThemeColor(getContext()));
indicatorNormalColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_normal_color, ResUtils.getColor(R.color.xui_config_color_black));
indicatorTextSize = getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_textSize, (int) indicatorTextSize);
indicatorVerticalLineWidth = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_vertical_line_w, indicatorVerticalLineWidth);
indicatorVerticalLineColor = typedArray.getColor(R.styleable.EasyIndicator_indicator_vertical_line_color, ThemeUtils.resolveColor(getContext(), R.attr.xui_config_color_separator_dark));
indicatorVerticalLineHeight = (int) getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_vertical_line_h, indicatorVerticalLineHeight);
indicatorSelectTextSize = getDimensionPixelSize(typedArray, R.styleable.EasyIndicator_indicator_select_textSize, 14);
typedArray.recycle();
// 指引器不能超过屏幕的宽度
indicatorWidth = Math.min(indicatorWidth, screenWidth);
if (indicatorWidth == 0) {
indicatorWidth = LayoutParams.MATCH_PARENT;
}
tabContent = new LinearLayout(getContext());
LayoutParams params = new LayoutParams(indicatorWidth, LayoutParams.WRAP_CONTENT);
tabContent.setBackgroundColor(Color.WHITE);
if (indicatorBgDrawable != null) {
tabContent.setBackground(indicatorBgDrawable);
} else {
tabContent.setBackgroundColor(Color.WHITE);
}
params.gravity = Gravity.CENTER;
tabContent.setLayoutParams(params);
tabContent.setGravity(Gravity.CENTER);
Expand Down Expand Up @@ -424,7 +427,9 @@ private void initScreenWidth() {
DisplayMetrics dm = getResources().getDisplayMetrics();
screenHeight = dm.heightPixels;
screenWidth = dm.widthPixels;

}

public LinearLayout getTabContent() {
return tabContent;
}
}
2 changes: 2 additions & 0 deletions xui_lib/src/main/res/values/xui_attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,8 @@
<attr name="indicator_width" format="dimension" />
<!--指示器的高度,默认45dp-->
<attr name="indicator_height" format="dimension" />
<!--指示器(整个Tab)的背景资源-->
<attr name="indicator_background" format="reference" />

<!--指示器文字的大小,默认14sp-->
<attr name="indicator_textSize" format="dimension" />
Expand Down

0 comments on commit 3fbbbe9

Please sign in to comment.