Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChayChan
BottomBarLayout
提交
3cc20bb1
B
BottomBarLayout
项目概览
ChayChan
/
BottomBarLayout
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
12
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
BottomBarLayout
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
12
Issue
12
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3cc20bb1
编写于
1月 05, 2018
作者:
穆弋
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BottomBarLayout add smoothScroll attribute
BottomBarItem add unreadNumThreshold attribute
上级
60341f65
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
26 deletion
+51
-26
library/src/main/java/com/chaychan/library/BottomBarItem.java
...ary/src/main/java/com/chaychan/library/BottomBarItem.java
+42
-26
library/src/main/java/com/chaychan/library/BottomBarLayout.java
...y/src/main/java/com/chaychan/library/BottomBarLayout.java
+4
-0
library/src/main/res/values/attr.xml
library/src/main/res/values/attr.xml
+5
-0
未找到文件。
library/src/main/java/com/chaychan/library/BottomBarItem.java
浏览文件 @
3cc20bb1
...
...
@@ -13,6 +13,8 @@ import android.widget.ImageView;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
java.util.Locale
;
/**
* @author ChayChan
...
...
@@ -45,7 +47,7 @@ public class BottomBarItem extends LinearLayout {
private
int
mUnreadTextSize
=
10
;
//未读数默认字体大小10sp
private
int
mMsgTextSize
=
6
;
//消息默认字体大小6sp
private
int
unreadNumThreshold
=
99
;
public
BottomBarItem
(
Context
context
)
{
this
(
context
,
null
);
...
...
@@ -66,7 +68,7 @@ public class BottomBarItem extends LinearLayout {
mIconSelectedResourceId
=
ta
.
getResourceId
(
R
.
styleable
.
BottomBarItem_iconSelected
,
-
1
);
mText
=
ta
.
getString
(
R
.
styleable
.
BottomBarItem_itemText
);
mTextSize
=
ta
.
getDimensionPixelSize
(
R
.
styleable
.
BottomBarItem_itemTextSize
,
UIUtils
.
sp2px
(
mContext
,
mTextSize
));
mTextSize
=
ta
.
getDimensionPixelSize
(
R
.
styleable
.
BottomBarItem_itemTextSize
,
UIUtils
.
sp2px
(
mContext
,
mTextSize
));
mTextColorNormal
=
ta
.
getColor
(
R
.
styleable
.
BottomBarItem_textColorNormal
,
mTextColorNormal
);
mTextColorSelected
=
ta
.
getColor
(
R
.
styleable
.
BottomBarItem_textColorSelected
,
mTextColorSelected
);
...
...
@@ -80,8 +82,9 @@ public class BottomBarItem extends LinearLayout {
mIconHeight
=
ta
.
getDimensionPixelSize
(
R
.
styleable
.
BottomBarItem_iconHeight
,
0
);
mItemPadding
=
ta
.
getDimensionPixelSize
(
R
.
styleable
.
BottomBarItem_itemPadding
,
0
);
mUnreadTextSize
=
ta
.
getDimensionPixelSize
(
R
.
styleable
.
BottomBarItem_unreadTextSize
,
UIUtils
.
sp2px
(
mContext
,
mUnreadTextSize
));
mMsgTextSize
=
ta
.
getDimensionPixelSize
(
R
.
styleable
.
BottomBarItem_msgTextSize
,
UIUtils
.
sp2px
(
mContext
,
mMsgTextSize
));
mUnreadTextSize
=
ta
.
getDimensionPixelSize
(
R
.
styleable
.
BottomBarItem_unreadTextSize
,
UIUtils
.
sp2px
(
mContext
,
mUnreadTextSize
));
mMsgTextSize
=
ta
.
getDimensionPixelSize
(
R
.
styleable
.
BottomBarItem_msgTextSize
,
UIUtils
.
sp2px
(
mContext
,
mMsgTextSize
));
unreadNumThreshold
=
ta
.
getInteger
(
R
.
styleable
.
BottomBarItem_unreadThreshold
,
99
);
ta
.
recycle
();
...
...
@@ -101,7 +104,7 @@ public class BottomBarItem extends LinearLayout {
throw
new
IllegalStateException
(
"您还没有设置选中状态下的图标,请指定iconSelected的图标"
);
}
if
(
mOpenTouchBg
&&
mTouchDrawable
==
null
){
if
(
mOpenTouchBg
&&
mTouchDrawable
==
null
)
{
//如果有开启触摸背景效果但是没有传对应的drawable
throw
new
IllegalStateException
(
"开启了触摸效果,但是没有指定touchDrawable"
);
}
...
...
@@ -112,9 +115,9 @@ public class BottomBarItem extends LinearLayout {
setGravity
(
Gravity
.
CENTER
);
View
view
=
View
.
inflate
(
mContext
,
R
.
layout
.
item_bottom_bar
,
null
);
if
(
mItemPadding
!=
0
){
if
(
mItemPadding
!=
0
)
{
//如果有设置item的padding
view
.
setPadding
(
mItemPadding
,
mItemPadding
,
mItemPadding
,
mItemPadding
);
view
.
setPadding
(
mItemPadding
,
mItemPadding
,
mItemPadding
,
mItemPadding
);
}
mImageView
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
iv_icon
);
mTvUnread
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
tv_unred_num
);
...
...
@@ -124,7 +127,7 @@ public class BottomBarItem extends LinearLayout {
mImageView
.
setImageResource
(
mIconNormalResourceId
);
if
(
mIconWidth
!=
0
&&
mIconHeight
!=
0
){
if
(
mIconWidth
!=
0
&&
mIconHeight
!=
0
)
{
//如果有设置图标的宽度和高度,则设置ImageView的宽高
FrameLayout
.
LayoutParams
imageLayoutParams
=
(
FrameLayout
.
LayoutParams
)
mImageView
.
getLayoutParams
();
imageLayoutParams
.
width
=
mIconWidth
;
...
...
@@ -132,9 +135,9 @@ public class BottomBarItem extends LinearLayout {
mImageView
.
setLayoutParams
(
imageLayoutParams
);
}
mTextView
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
mTextSize
);
//设置底部文字字体大小
mTvUnread
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
mUnreadTextSize
);
//设置未读数的字体大小
mTvMsg
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
mMsgTextSize
);
//设置提示文字的字体大小
mTextView
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
mTextSize
);
//设置底部文字字体大小
mTvUnread
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
mUnreadTextSize
);
//设置未读数的字体大小
mTvMsg
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
mMsgTextSize
);
//设置提示文字的字体大小
mTextView
.
setTextColor
(
mTextColorNormal
);
//设置底部文字字体颜色
mTextView
.
setText
(
mText
);
//设置标签文字
...
...
@@ -143,7 +146,7 @@ public class BottomBarItem extends LinearLayout {
textLayoutParams
.
topMargin
=
mMarginTop
;
mTextView
.
setLayoutParams
(
textLayoutParams
);
if
(
mOpenTouchBg
){
if
(
mOpenTouchBg
)
{
//如果有开启触摸背景
setBackground
(
mTouchDrawable
);
}
...
...
@@ -167,12 +170,12 @@ public class BottomBarItem extends LinearLayout {
this
.
mIconSelectedResourceId
=
mIconSelectedResourceId
;
}
public
void
setStatus
(
boolean
isSelected
){
mImageView
.
setImageResource
(
isSelected
?
mIconSelectedResourceId:
mIconNormalResourceId
);
mTextView
.
setTextColor
(
isSelected
?
mTextColorSelected:
mTextColorNormal
);
public
void
setStatus
(
boolean
isSelected
)
{
mImageView
.
setImageResource
(
isSelected
?
mIconSelectedResourceId
:
mIconNormalResourceId
);
mTextView
.
setTextColor
(
isSelected
?
mTextColorSelected
:
mTextColorNormal
);
}
private
void
setTvVisiable
(
TextView
tv
){
private
void
setTvVisiable
(
TextView
tv
)
{
//都设置为不可见
mTvUnread
.
setVisibility
(
GONE
);
mTvMsg
.
setVisibility
(
GONE
);
...
...
@@ -181,34 +184,47 @@ public class BottomBarItem extends LinearLayout {
tv
.
setVisibility
(
VISIBLE
);
//设置为可见
}
public
int
getUnreadNumThreshold
()
{
return
unreadNumThreshold
;
}
public
void
setUnreadNumThreshold
(
int
unreadNumThreshold
)
{
this
.
unreadNumThreshold
=
unreadNumThreshold
;
}
/**
* 设置未读数
* @param unreadNum 小于等于0则隐藏,大于0小于99则显示对应数字,超过99显示99+
*
* @param unreadNum 小于等于{@link com.chaychan.library.BottomBarItem#unreadNumThreshold}则隐藏,
* 大于0小于{@link com.chaychan.library.BottomBarItem#unreadNumThreshold}则显示对应数字,
* 超过{@link com.chaychan.library.BottomBarItem#unreadNumThreshold}
* 显示{@link com.chaychan.library.BottomBarItem#unreadNumThreshold}+
*/
public
void
setUnreadNum
(
int
unreadNum
){
public
void
setUnreadNum
(
int
unreadNum
)
{
setTvVisiable
(
mTvUnread
);
if
(
unreadNum
<=
0
){
if
(
unreadNum
<=
0
)
{
mTvUnread
.
setVisibility
(
GONE
);
}
else
if
(
unreadNum
<=
99
)
{
}
else
if
(
unreadNum
<=
unreadNumThreshold
)
{
mTvUnread
.
setText
(
String
.
valueOf
(
unreadNum
));
}
else
{
mTvUnread
.
setText
(
"99+"
);
}
else
{
mTvUnread
.
setText
(
String
.
format
(
Locale
.
CHINA
,
"%d+"
,
unreadNum
)
);
}
}
public
void
setMsg
(
String
msg
){
public
void
setMsg
(
String
msg
)
{
setTvVisiable
(
mTvMsg
);
mTvMsg
.
setText
(
msg
);
}
public
void
hideMsg
(){
public
void
hideMsg
()
{
mTvMsg
.
setVisibility
(
GONE
);
}
public
void
showNotify
(){
public
void
showNotify
()
{
setTvVisiable
(
mTvNotify
);
}
public
void
hideNotify
(){
public
void
hideNotify
()
{
mTvNotify
.
setVisibility
(
GONE
);
}
}
library/src/main/java/com/chaychan/library/BottomBarLayout.java
浏览文件 @
3cc20bb1
package
com.chaychan.library
;
import
android.content.Context
;
import
android.content.res.TypedArray
;
import
android.os.Bundle
;
import
android.os.Parcelable
;
import
android.support.v4.view.ViewPager
;
...
...
@@ -38,6 +39,9 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha
public
BottomBarLayout
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
TypedArray
ta
=
context
.
obtainStyledAttributes
(
attrs
,
R
.
styleable
.
BottomBarLayout
);
mSmoothScroll
=
ta
.
getBoolean
(
R
.
styleable
.
BottomBarLayout_smoothScroll
,
true
);
ta
.
recycle
();
setOrientation
(
HORIZONTAL
);
}
...
...
library/src/main/res/values/attr.xml
浏览文件 @
3cc20bb1
...
...
@@ -29,5 +29,10 @@
<attr
name=
"unreadTextSize"
format=
"dimension"
/>
<!--设置提示消息字体大小-->
<attr
name=
"msgTextSize"
format=
"dimension"
/>
<!--设置未读数组阈值 大于阈值的数字将显示为 n+ n为设置的阈值-->
<attr
name=
"unreadThreshold"
format=
"integer"
/>
</declare-styleable>
<declare-styleable
name=
"BottomBarLayout"
>
<attr
name=
"smoothScroll"
format=
"boolean"
/>
</declare-styleable>
</resources>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录