仿QQ微信底部的带消息数量
来源:互联网 发布:淘宝卖家信用度 编辑:程序博客网 时间:2024/05/14 18:19
原创~~~仿QQ微信底部的带消息数量
菜鸟的起飞之路
问题思路:
1.利用FragmentTabhost 作为主页面, 下方三个切换按钮
2.用每个按钮为一个view ,view 的布局如下图1
3.每个切换view的图片写一个selector,作为页面切换画面
4.在view中,右上角有一个textview,作为可变的消息数目
,
图1, tabhost_item 的布局如下
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:paddingTop="5dp" android:paddingBottom="5dp" android:orientation="vertical"><FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:focusable="false" android:scaleType="centerInside" android:src="@drawable/contacts"> </ImageView> <TextView android:id="@+id/main_tab_unread_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bg_new_msg_count" android:gravity="center" android:textSize="6dp" android:padding="2dp" android:textColor="@android:color/white" android:visibility="invisible" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/imageview" android:layout_toEndOf="@+id/imageview" android:layout_gravity="right|top" /></FrameLayout> <TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@drawable/common_tab_color" android:textSize="10sp"></TextView></LinearLayout>
5.在activity中设置,将main_tab_unread_tv赋值给全局变量tv_count,并进行赋值
/** * 给Tab按钮设置图标和文字 */ private View getTabItemView(int index) { View view = layoutInflater.inflate(R.layout.tabhost_item, null); ImageView imageView = (ImageView) view.findViewById(R.id.imageview); imageView.setImageResource(mImageViewArray[index]); TextView main_tab_unread_tv = (TextView) view.findViewById(R.id.main_tab_unread_tv); TextView textView = (TextView) view.findViewById(R.id.textview); textView.setText(tabHostTagArray[index]); if (index == 0) {//假如仅有通知界面需要显示消息数,提取tv_count作为全局变量进行操作,隐藏或显示 tv_count=main_tab_unread_tv; if (counts>0){ tv_count.setVisibility(View.VISIBLE); tv_count.setText(counts+""); }else{ tv_count.setVisibility(View.INVISIBLE); } } return view; } public void setMegWidget(int megWidget) { Log.e("setMegWidget~~~~~~~", "megWidget" + counts); if (counts>0) { tv_count.setVisibility(View.VISIBLE); tv_count.setText(counts+""); }else { tv_count.setVisibility(View.INVISIBLE); } } public void notifyMsgChanged(int count) {//在massagefragment中调用,或者请求网络查看 未读消息个数, counts=count; setMegWidget(counts); }
6.在fragment中进行更新,进行赋值
private void initView(View view) {//在massagefragment中调用,或者请求网络查看 未读消息个数, ////模拟调用 添加 模拟数据 mainActivity. notifyMsgChanged(2);//假设接收到两个未读消息 }
附带Demo github地址:https://github.com/ccj659/QQTabDemo.git
1 0
- 仿QQ微信底部的带消息数量
- Android实现微信底部的带消息提示数量
- Android实现微信底部的带消息提示数量
- Android实现微信底部的带消息提示数量
- android仿qq微信的消息数量显示功能
- Android高仿qq及微信底部菜单的几种实现方式
- Android高仿QQ及微信底部菜单的多种实现方式【附源码地址】
- 【附源码地址】Android高仿QQ及微信底部菜单的多种实现方式
- 带消息数量的TabLayout
- 仿QQ页面右侧底部弹出消息窗口
- 仿qq底部的提示标记
- 类似qq,微信的消息提醒
- 类似QQ的提示消息数量
- Android实用视图动画及工具系列之五:底部回复对话框,仿QQ空间微信朋友圈回复对话框
- 仿QQ底部弹出效果
- 仿qq底部Tab导航
- 仿qq底部Tab导航
- 仿 QQ 底部 tab 导航
- 四种强制类型转换的总结(const_cast、static_cast、dynamic_cast、reinterpreter_cast)
- 【学习笔记】Java抽象类和接口的一些总结
- compareTo()方法返回值 String java
- 自动化清理Android中无用的资源文件。
- Java中的10颗语法糖
- 仿QQ微信底部的带消息数量
- java 汉字按照拼音排序
- Apache Shiro 使用手册
- JTAG调试原理
- 如何让sublime text 2 支持livescript
- iOS7 TextKit 框架的简单实用
- Eclipse快捷键 10个最有用的快捷键
- Beaglebone Black教程BeagleBone Black安装最新系统映像
- 虚拟IP技术 ip地址漂移技术