Skip to content

Commit

Permalink
1. bugfix: the icon not display when icon position is bottom; 2. add …
Browse files Browse the repository at this point in the history
…method to control icon position in java #116
  • Loading branch information
cgspine committed Dec 20, 2017
1 parent f9e74cb commit 9465894
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
32 changes: 24 additions & 8 deletions qmui/src/main/java/com/qmuiteam/qmui/widget/QMUITabSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ public class QMUITabSegment extends HorizontalScrollView {
public static final int MODE_SCROLLABLE = 0;
public static final int MODE_FIXED = 1;
// icon position
private static final int ICON_POSITION_LEFT = 0;
private static final int ICON_POSITION_TOP = 1;
private static final int ICON_POSITION_RIGHT = 2;
private static final int ICON_POSITION_BOTTOM = 4;
public static final int ICON_POSITION_LEFT = 0;
public static final int ICON_POSITION_TOP = 1;
public static final int ICON_POSITION_RIGHT = 2;
public static final int ICON_POSITION_BOTTOM = 3;
// status: 用于记录tab的改变状态
private static final int STATUS_NORMAL = 0;
private static final int STATUS_PROGRESS = 1;
Expand Down Expand Up @@ -146,11 +146,11 @@ public class QMUITabSegment extends HorizontalScrollView {
/**
* item icon的默认位置
*/
private int mTabIconPosition;
@IconPosition private int mDefaultTabIconPosition;
/**
* TabSegmentMode
*/
private int mMode = MODE_FIXED;
@Mode private int mMode = MODE_FIXED;
/**
* ScrollMode下item的间隙
*/
Expand Down Expand Up @@ -220,7 +220,7 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
mTabTextSize = array.getDimensionPixelSize(R.styleable.QMUITabSegment_android_textSize,
getResources().getDimensionPixelSize(R.dimen.qmui_tab_segment_text_size));
mIndicatorTop = array.getBoolean(R.styleable.QMUITabSegment_qmui_tab_indicator_top, false);
mTabIconPosition = array.getInt(R.styleable.QMUITabSegment_qmui_tab_icon_position, ICON_POSITION_LEFT);
mDefaultTabIconPosition = array.getInt(R.styleable.QMUITabSegment_qmui_tab_icon_position, ICON_POSITION_LEFT);
mMode = array.getInt(R.styleable.QMUITabSegment_qmui_tab_mode, MODE_FIXED);
mItemSpaceInScrollMode = array.getDimensionPixelSize(R.styleable.QMUITabSegment_qmui_tab_space, QMUIDisplayHelper.dp2px(context, 10));
typefaceProviderName = array.getString(R.styleable.QMUITabSegment_qmui_tab_typeface_provider);
Expand Down Expand Up @@ -505,6 +505,13 @@ public void setDefaultSelectedColor(@ColorInt int defaultSelectedColor) {
mDefaultSelectedColor = defaultSelectedColor;
}

/**
* @param defaultTabIconPosition
*/
public void setDefaultTabIconPosition(@IconPosition int defaultTabIconPosition) {
mDefaultTabIconPosition = defaultTabIconPosition;
}

private void preventLayoutToChangeTabColor(TextView textView, int color, Tab model, int status) {
mForceIndicatorNotDoLayoutWhenParentLayout = true;
changeTabColor(textView, color, model, status);
Expand Down Expand Up @@ -753,7 +760,7 @@ private int getTabNormalColor(Tab item) {
private int getTabIconPosition(Tab item) {
int iconPosition = item.getIconPosition();
if (iconPosition == Tab.USE_TAB_SEGMENT) {
iconPosition = mTabIconPosition;
iconPosition = mDefaultTabIconPosition;
}
return iconPosition;
}
Expand Down Expand Up @@ -874,6 +881,11 @@ public int getSignCount(int index) {
public @interface Mode {
}

@IntDef(value = {ICON_POSITION_LEFT, ICON_POSITION_TOP, ICON_POSITION_RIGHT, ICON_POSITION_BOTTOM})
@Retention(RetentionPolicy.SOURCE)
public @interface IconPosition {
}

public interface OnTabClickListener {
/**
* 当某个 Tab 被点击时会触发
Expand Down Expand Up @@ -1067,6 +1079,10 @@ public int getIconPosition() {
return iconPosition;
}

public void setIconPosition(int iconPosition) {
this.iconPosition = iconPosition;
}

public int getGravity() {
return gravity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private void initTabs() {
int selectColor = QMUIResHelper.getAttrColor(getActivity(), R.attr.qmui_config_color_blue);
mTabSegment.setDefaultNormalColor(normalColor);
mTabSegment.setDefaultSelectedColor(selectColor);
// mTabSegment.setDefaultTabIconPosition(QMUITabSegment.ICON_POSITION_BOTTOM);
QMUITabSegment.Tab component = new QMUITabSegment.Tab(
ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component),
ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component_selected),
Expand Down

0 comments on commit 9465894

Please sign in to comment.