Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChayChan
BottomBarLayout
提交
e4c8b3d0
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 搜索 >>
提交
e4c8b3d0
编写于
9月 10, 2017
作者:
C
chaychan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加设置未读数、提示小红点、提示消息的功能
上级
ac08f332
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
181 addition
and
14 deletion
+181
-14
demo/src/main/java/com/chaychan/bottombarlayout/MainActivity.java
.../main/java/com/chaychan/bottombarlayout/MainActivity.java
+5
-0
library/build.gradle
library/build.gradle
+1
-1
library/src/main/java/com/chaychan/library/BottomBarItem.java
...ary/src/main/java/com/chaychan/library/BottomBarItem.java
+60
-6
library/src/main/java/com/chaychan/library/BottomBarLayout.java
...y/src/main/java/com/chaychan/library/BottomBarLayout.java
+42
-0
library/src/main/res/drawable/shape_notify_point.xml
library/src/main/res/drawable/shape_notify_point.xml
+9
-0
library/src/main/res/drawable/shape_unread.xml
library/src/main/res/drawable/shape_unread.xml
+6
-0
library/src/main/res/layout/item_bottom_bar.xml
library/src/main/res/layout/item_bottom_bar.xml
+53
-7
library/src/main/res/values/attr.xml
library/src/main/res/values/attr.xml
+4
-0
library/src/main/res/values/colors.xml
library/src/main/res/values/colors.xml
+1
-0
未找到文件。
demo/src/main/java/com/chaychan/bottombarlayout/MainActivity.java
浏览文件 @
e4c8b3d0
...
...
@@ -113,6 +113,11 @@ public class MainActivity extends FragmentActivity {
cancelTabLoading
(
bottomItem
);
//停止旋转动画
}
});
mBottomBarLayout
.
setUnread
(
0
,
20
);
//设置第一个页签的未读数为20
mBottomBarLayout
.
setUnread
(
1
,
101
);
//设置第二个页签的未读书
mBottomBarLayout
.
showNotify
(
2
);
//设置第三个页签显示提示的小红点
mBottomBarLayout
.
setMsg
(
3
,
"NEW"
);
//设置第四个页签显示NEW提示文字
}
/**停止首页页签的旋转动画*/
...
...
library/build.gradle
浏览文件 @
e4c8b3d0
...
...
@@ -22,7 +22,7 @@ android {
}
dependencies
{
compile
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
]
)
compile
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
androidTestCompile
(
'com.android.support.test.espresso:espresso-core:2.2.2'
,
{
exclude
group:
'com.android.support'
,
module:
'support-annotations'
})
...
...
library/src/main/java/com/chaychan/library/BottomBarItem.java
浏览文件 @
e4c8b3d0
...
...
@@ -5,6 +5,7 @@ import android.content.res.TypedArray;
import
android.graphics.drawable.Drawable
;
import
android.support.annotation.Nullable
;
import
android.util.AttributeSet
;
import
android.util.TypedValue
;
import
android.view.Gravity
;
import
android.view.View
;
import
android.widget.ImageView
;
...
...
@@ -12,7 +13,6 @@ import android.widget.LinearLayout;
import
android.widget.TextView
;
/**
* @author ChayChan
* @description: 底部tab条目
...
...
@@ -35,9 +35,15 @@ public class BottomBarItem extends LinearLayout {
private
int
mIconHeight
;
//图标的高度
private
int
mItemPadding
;
//BottomBarItem的padding
private
TextView
mTextView
;
private
ImageView
mImageView
;
private
TextView
mTvUnread
;
private
TextView
mTvNotify
;
private
TextView
mTvMsg
;
private
TextView
mTextView
;
private
int
mUnreadTextSize
=
10
;
//未读数默认字体大小10sp
private
int
mMsgTextSize
=
6
;
//消息默认字体大小6sp
public
BottomBarItem
(
Context
context
)
{
...
...
@@ -73,6 +79,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
));
ta
.
recycle
();
checkValues
();
...
...
@@ -107,9 +116,11 @@ public class BottomBarItem extends LinearLayout {
view
.
setPadding
(
mItemPadding
,
mItemPadding
,
mItemPadding
,
mItemPadding
);
}
mImageView
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
iv_icon
);
mTvUnread
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
tv_unred_num
);
mTvMsg
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
tv_msg
);
mTvNotify
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
tv_point
);
mTextView
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
tv_text
);
mImageView
.
setImageResource
(
mIconNormalResourceId
);
if
(
mIconWidth
!=
0
&&
mIconHeight
!=
0
){
...
...
@@ -120,9 +131,12 @@ public class BottomBarItem extends LinearLayout {
mImageView
.
setLayoutParams
(
imageLayoutParams
);
}
mTextView
.
getPaint
().
setTextSize
(
mTextSize
);
mTextView
.
setText
(
mText
);
mTextView
.
setTextColor
(
mTextColorNormal
);
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
);
//设置标签文字
LayoutParams
textLayoutParams
=
(
LayoutParams
)
mTextView
.
getLayoutParams
();
textLayoutParams
.
topMargin
=
mMarginTop
;
...
...
@@ -156,4 +170,44 @@ public class BottomBarItem extends LinearLayout {
mImageView
.
setImageResource
(
isSelected
?
mIconSelectedResourceId:
mIconNormalResourceId
);
mTextView
.
setTextColor
(
isSelected
?
mTextColorSelected:
mTextColorNormal
);
}
private
void
setTvVisiable
(
TextView
tv
){
//都设置为不可见
mTvUnread
.
setVisibility
(
GONE
);
mTvMsg
.
setVisibility
(
GONE
);
mTvNotify
.
setVisibility
(
GONE
);
tv
.
setVisibility
(
VISIBLE
);
//设置为可见
}
/**
* 设置未读数
* @param unreadNum 小于等于0则隐藏,大于0小于99则显示对应数字,超过99显示99+
*/
public
void
setUnreadNum
(
int
unreadNum
){
setTvVisiable
(
mTvUnread
);
if
(
unreadNum
<=
0
){
mTvUnread
.
setVisibility
(
GONE
);
}
else
if
(
unreadNum
<=
99
){
mTvUnread
.
setText
(
String
.
valueOf
(
unreadNum
));
}
else
{
mTvUnread
.
setText
(
"99+"
);
}
}
public
void
setMsg
(
String
msg
){
setTvVisiable
(
mTvMsg
);
mTvMsg
.
setText
(
msg
);
}
public
void
hideMsg
(){
mTvMsg
.
setVisibility
(
GONE
);
}
public
void
showNotify
(){
setTvVisiable
(
mTvNotify
);
}
public
void
hideNotify
(){
mTvNotify
.
setVisibility
(
GONE
);
}
}
library/src/main/java/com/chaychan/library/BottomBarLayout.java
浏览文件 @
e4c8b3d0
...
...
@@ -136,6 +136,48 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha
mViewPager
.
setCurrentItem
(
mCurrentItem
,
mSmoothScroll
);
}
/**
* 设置未读数
* @param position 底部标签的下标
* @param unreadNum 未读数
*/
public
void
setUnread
(
int
position
,
int
unreadNum
){
mItemViews
.
get
(
position
).
setUnreadNum
(
unreadNum
);
}
/**
* 设置提示消息
* @param position 底部标签的下标
* @param msg 未读数
*/
public
void
setMsg
(
int
position
,
String
msg
){
mItemViews
.
get
(
position
).
setMsg
(
msg
);
}
/**
* 隐藏提示消息
* @param position 底部标签的下标
*/
public
void
hideMsg
(
int
position
){
mItemViews
.
get
(
position
).
hideMsg
();
}
/**
* 显示提示的小红点
* @param position 底部标签的下标
*/
public
void
showNotify
(
int
position
){
mItemViews
.
get
(
position
).
showNotify
();
}
/**
* 隐藏提示的小红点
* @param position 底部标签的下标
*/
public
void
hideNotify
(
int
position
){
mItemViews
.
get
(
position
).
hideNotify
();
}
public
int
getCurrentItem
()
{
return
mCurrentItem
;
}
...
...
library/src/main/res/drawable/shape_notify_point.xml
0 → 100644
浏览文件 @
e4c8b3d0
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"oval"
>
<solid
android:color=
"@color/red"
/>
<size
android:width=
"10dp"
android:height=
"10dp"
/>
</shape>
\ No newline at end of file
library/src/main/res/drawable/shape_unread.xml
0 → 100644
浏览文件 @
e4c8b3d0
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<corners
android:radius=
"20dp"
/>
<solid
android:color=
"@color/red"
/>
<padding
android:left=
"4dp"
android:right=
"4dp"
android:top=
"1dp"
android:bottom=
"1dp"
/>
</shape>
\ No newline at end of file
library/src/main/res/layout/item_bottom_bar.xml
浏览文件 @
e4c8b3d0
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:gravity=
"center"
android:orientation=
"vertical"
>
<ImageView
android:id=
"@+id/iv_icon"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
/>
<FrameLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<ImageView
android:id=
"@+id/iv_icon"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
/>
<TextView
android:id=
"@+id/tv_unred_num"
android:layout_width=
"wrap_content"
android:minWidth=
"15dp"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:layout_marginLeft=
"14dp"
android:background=
"@drawable/shape_unread"
android:gravity=
"center"
android:text=
"99+"
android:textColor=
"@color/white"
android:textSize=
"10sp"
android:visibility=
"gone"
/>
<TextView
android:id=
"@+id/tv_msg"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:layout_marginLeft=
"14dp"
android:background=
"@drawable/shape_unread"
android:gravity=
"center"
android:text=
"NEW"
android:textColor=
"@color/white"
android:textSize=
"6sp"
android:visibility=
"gone"
/>
<TextView
android:id=
"@+id/tv_point"
android:layout_width=
"10dp"
android:layout_height=
"10dp"
android:layout_gravity=
"center_horizontal"
android:layout_marginLeft=
"10dp"
android:background=
"@drawable/shape_notify_point"
android:gravity=
"center"
android:textSize=
"6sp"
android:visibility=
"gone"
/>
</FrameLayout>
<TextView
android:id=
"@+id/tv_text"
...
...
library/src/main/res/values/attr.xml
浏览文件 @
e4c8b3d0
...
...
@@ -25,5 +25,9 @@
<attr
name=
"iconHeight"
format=
"dimension"
/>
<!--设置BottomBarItem的padding-->
<attr
name=
"itemPadding"
format=
"dimension"
/>
<!--设置未读数字体大小-->
<attr
name=
"unreadTextSize"
format=
"dimension"
/>
<!--设置提示消息字体大小-->
<attr
name=
"msgTextSize"
format=
"dimension"
/>
</declare-styleable>
</resources>
\ No newline at end of file
library/src/main/res/values/colors.xml
浏览文件 @
e4c8b3d0
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color
name=
"white"
>
#ffffff
</color>
<color
name=
"red"
>
#ff0000
</color>
<color
name=
"selector_grey"
>
#DDDDDD
</color>
</resources>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录