diff --git a/demo/src/main/java/com/chaychan/bottombarlayout/DynamicAddItemActivity.java b/demo/src/main/java/com/chaychan/bottombarlayout/DynamicAddItemActivity.java index 16c40af..d291cd9 100644 --- a/demo/src/main/java/com/chaychan/bottombarlayout/DynamicAddItemActivity.java +++ b/demo/src/main/java/com/chaychan/bottombarlayout/DynamicAddItemActivity.java @@ -83,6 +83,7 @@ private TabFragment createFragment(int titleId) { private BottomBarItem createBottomBarItem(int i) { BottomBarItem item = new BottomBarItem.Builder(this) + .titleTextBold(true) .titleTextSize(8) .titleNormalColor(R.color.tab_normal_color) .titleSelectedColor(R.color.tab_selected_color) diff --git a/demo/src/main/res/layout/activity_fragment_manager.xml b/demo/src/main/res/layout/activity_fragment_manager.xml index da6dcb2..691e2e2 100644 --- a/demo/src/main/res/layout/activity_fragment_manager.xml +++ b/demo/src/main/res/layout/activity_fragment_manager.xml @@ -31,6 +31,7 @@ app:iconNormal="@mipmap/tab_home_normal" app:iconSelected="@mipmap/tab_home_selected" app:itemText="@string/tab_home" + app:itemTextBold="true" app:textColorNormal="@color/tab_normal_color" app:textColorSelected="@color/tab_selected_color" app:itemTextSize="8sp" @@ -46,6 +47,7 @@ app:iconNormal="@mipmap/tab_video_normal" app:iconSelected="@mipmap/tab_video_selected" app:itemText="@string/tab_video" + app:itemTextBold="true" app:textColorNormal="@color/tab_normal_color" app:textColorSelected="@color/tab_selected_color" app:itemTextSize="8sp" @@ -63,6 +65,7 @@ app:iconNormal="@mipmap/tab_micro_normal" app:iconSelected="@mipmap/tab_micro_selected" app:itemText="@string/tab_micro" + app:itemTextBold="true" app:textColorNormal="@color/tab_normal_color" app:textColorSelected="@color/tab_selected_color" app:itemTextSize="8sp" @@ -78,6 +81,7 @@ app:iconNormal="@mipmap/tab_me_normal" app:iconSelected="@mipmap/tab_me_selected" app:itemText="@string/tab_me" + app:itemTextBold="true" app:textColorNormal="@color/tab_normal_color" app:textColorSelected="@color/tab_selected_color" app:itemTextSize="8sp" diff --git a/library/src/main/java/com/chaychan/library/BottomBarItem.java b/library/src/main/java/com/chaychan/library/BottomBarItem.java index 5120066..d96ed89 100644 --- a/library/src/main/java/com/chaychan/library/BottomBarItem.java +++ b/library/src/main/java/com/chaychan/library/BottomBarItem.java @@ -29,6 +29,7 @@ public class BottomBarItem extends LinearLayout { private Drawable normalIcon;//普通状态图标的资源id private Drawable selectedIcon;//选中状态图标的资源id private String title;//文本 + private boolean titleTextBold = false;//文字加粗 private int titleTextSize = 12;//文字大小 默认为12sp private int titleNormalColor; //描述文本的默认显示颜色 private int titleSelectedColor; //述文本的默认选中显示颜色 @@ -83,6 +84,7 @@ private void initAttrs(TypedArray ta) { selectedIcon = ta.getDrawable(R.styleable.BottomBarItem_iconSelected); title = ta.getString(R.styleable.BottomBarItem_itemText); + titleTextBold = ta.getBoolean(R.styleable.BottomBarItem_itemTextBold, titleTextBold); titleTextSize = ta.getDimensionPixelSize(R.styleable.BottomBarItem_itemTextSize, UIUtils.sp2px(context, titleTextSize)); titleNormalColor = ta.getColor(R.styleable.BottomBarItem_textColorNormal, UIUtils.getColor(context,R.color.bbl_999999)); @@ -157,7 +159,7 @@ private void init() { } mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);//设置底部文字字体大小 - + mTextView.getPaint().setFakeBoldText(titleTextBold); mTvUnread.setTextSize(TypedValue.COMPLEX_UNIT_PX, unreadTextSize);//设置未读数的字体大小 mTvUnread.setTextColor(unreadTextColor);//设置未读数字体颜色 mTvUnread.setBackground(unreadTextBg);//设置未读数背景 @@ -284,6 +286,7 @@ public BottomBarItem create(Builder builder) { this.normalIcon = builder.normalIcon; this.selectedIcon = builder.selectedIcon; this.title = builder.title; + this.titleTextBold = builder.titleTextBold; this.titleTextSize = builder.titleTextSize; this.titleNormalColor = builder.titleNormalColor; this.titleSelectedColor = builder.titleSelectedColor; @@ -312,6 +315,7 @@ public static final class Builder { private Drawable normalIcon;//普通状态图标的资源id private Drawable selectedIcon;//选中状态图标的资源id private String title;//标题 + private boolean titleTextBold;//文字加粗 private int titleTextSize;//字体大小 private int titleNormalColor; //描述文本的默认显示颜色 private int titleSelectedColor; //述文本的默认选中显示颜色 @@ -332,6 +336,7 @@ public static final class Builder { public Builder(Context context) { this.context = context; + titleTextBold = false; titleTextSize = UIUtils.sp2px(context,12); titleNormalColor = getColor(R.color.bbl_999999); titleSelectedColor = getColor(R.color.bbl_ff0000); @@ -374,6 +379,14 @@ public Builder title(String title) { return this; } + /** + * Sets the title's text bold + */ + public Builder titleTextBold(boolean titleTextBold) { + this.titleTextBold = titleTextBold; + return this; + } + /** * Sets the title's text size */ diff --git a/library/src/main/java/com/chaychan/library/BottomBarLayout.java b/library/src/main/java/com/chaychan/library/BottomBarLayout.java index 2c7037d..184ee2f 100644 --- a/library/src/main/java/com/chaychan/library/BottomBarLayout.java +++ b/library/src/main/java/com/chaychan/library/BottomBarLayout.java @@ -4,6 +4,7 @@ import android.content.res.TypedArray; import android.os.Bundle; import android.os.Parcelable; +import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.View; @@ -67,7 +68,8 @@ private void init() { } if (mViewPager != null) { - if (mViewPager.getAdapter().getCount() != mChildCount) { + PagerAdapter adapter = mViewPager.getAdapter(); + if (adapter != null && adapter.getCount() != mChildCount) { throw new IllegalArgumentException("LinearLayout的子View数量必须和ViewPager条目数量一致"); } } diff --git a/library/src/main/res/values/attr.xml b/library/src/main/res/values/attr.xml index dc09691..b2b4662 100644 --- a/library/src/main/res/values/attr.xml +++ b/library/src/main/res/values/attr.xml @@ -10,6 +10,8 @@ + + @@ -56,4 +58,4 @@ - \ No newline at end of file +