安卓微信 返回显示未读条数_Android仿微信底部菜单栏功能显示未读消息数量
底部菜单栏很重要,我看了一下很多应用软件都是用了底部菜单栏,这里使用了tabhost做了一种通用的(就是可以像微信那样显示未读消息数量的,虽然之前也做过但是layout下的xml写的太臃肿,这里去掉了很多不必要的层,个人看起来还是不错的,所以贴出来方便以后使用)。
先看一下做出来之后的效果:
以后使用的时候就可以换成自己项目的图片和字体了,主框架不用变哈哈,
首先是要布局layout下xml文件 main.xml:
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/bg_gray"
android:orientation="vertical" >
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_weight="1.0" />
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:visibility="gone" />
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
android:id="@+id/main_tab_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/bottom1"
android:gravity="bottom"
android:orientation="horizontal"
>
android:id="@+id/main_tab_addExam"
style="@style/MMTabButton"
android:layout_weight="1.0"
android:drawableTop="@drawable/bg_checkbox_icon_menu_0"
android:text="添加考试" />
android:id="@+id/main_tab_myExam"
style="@style/MMTabButton"
android:layout_weight="1.0"
android:checked="true"
android:drawableTop="@drawable/bg_checkbox_icon_menu_1"
android:text="我的考试" />
android:id="@+id/main_tab_message"
style="@style/MMTabButton"
android:layout_weight="1.0"
android:drawableTop="@drawable/bg_checkbox_icon_menu_2"
android:text="我的通知" />
android:id="@+id/main_tab_settings"
style="@style/MMTabButton"
android:layout_weight="1.0"
android:drawableTop="@drawable/bg_checkbox_icon_menu_3"
android:text="设置" />
android:id="@+id/main_tab_new_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:layout_marginLeft="60dip"
android:layout_marginTop="1dip"
android:background="@drawable/tips"
android:gravity="center"
android:text="1"
android:textColor="#ffffff"
android:textSize="10sp"
android:visibility="gone" />
在RadioGroup的外面加了一个FrameLayout,主要是为了使用TextView显示消息数量,这里是居中靠左60dip,可能你会问直接写死能支持多分辨率吗,这个我在320*480的手机上试过没问题的,因为dip是与设备无关的支持多分辨率,至于1280*800平板电脑这样的分辨率我就不能保证了,哈哈!
接下来是样式布局:
12.0dip
center_horizontal
@drawable/bg_checkbox_menus
fill_parent
wrap_content
@null
@color/white
1.0
2.0dip
2.0dip
在drawable下bg_checkbox_menus.xml
android:state_checked="false"
android:drawable="@drawable/mm_trans" />
android:state_checked="true"
android:drawable="@drawable/home_btn_bg" />
其他的那四个都合这个一样点击后图片换成亮色的,所以就不一一贴出来了。
最后看MainActivity这个类:
package cn.com.karl.test;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TextView;
public class MainActivity extends TabActivity {
/** Called when the activity is first created. */
private TabHost tabHost;
private TextView main_tab_new_message;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
main_tab_new_message=(TextView) findViewById(R.id.main_tab_new_message);
main_tab_new_message.setVisibility(View.VISIBLE);
main_tab_new_message.setText("10");
tabHost=this.getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent=new Intent().setClass(this, AddExamActivity.class);
spec=tabHost.newTabSpec("添加考试").setIndicator("添加考试").setContent(intent);
tabHost.addTab(spec);
intent=new Intent().setClass(this,MyExamActivity.class);
spec=tabHost.newTabSpec("我的考试").setIndicator("我的考试").setContent(intent);
tabHost.addTab(spec);
intent=new Intent().setClass(this, MyMessageActivity.class);
spec=tabHost.newTabSpec("我的通知").setIndicator("我的通知").setContent(intent);
tabHost.addTab(spec);
intent=new Intent().setClass(this, SettingActivity.class);
spec=tabHost.newTabSpec("设置").setIndicator("设置").setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
RadioGroup radioGroup=(RadioGroup) this.findViewById(R.id.main_tab_group);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.main_tab_addExam://添加考试
tabHost.setCurrentTabByTag("添加考试");
break;
case R.id.main_tab_myExam://我的考试
tabHost.setCurrentTabByTag("我的考试");
break;
case R.id.main_tab_message://我的通知
tabHost.setCurrentTabByTag("我的通知");
break;
case R.id.main_tab_settings://设置
tabHost.setCurrentTabByTag("设置");
break;
default:
//tabHost.setCurrentTabByTag("我的考试");
break;
}
}
});
}
}
这样就完成了,主要还是使用了tabhost完成,tabhost有缓存机制这四个界面都会缓存到内存中,这样即有利也有弊,有利是因为切换的时候不用在重新加载了,有弊是因为缓存四个界面会耗费内存较多一些。如果只想缓存一个界面,大家可以参考这篇文章:Android项目实战之仿网易顶部导航栏效果,使用ActivityGroup实现顶部滑动栏,就像网易新闻的顶部滑动栏我相信也是只缓存了一个界面,切换的时候是从数据库加载的,所以第二次滑动加载会比较快。
以上就是本文的全部内容,希望能给大家一个参考,也希望大家多多支持脚本之家。
安卓微信 返回显示未读条数_Android仿微信底部菜单栏功能显示未读消息数量相关推荐
- android仿微信图片上传进度,Android开发之模仿微信打开网页的进度条效果(高仿)...
一,为什么说是真正的高仿? 阐述这个问题前,先说下之前网上的,各位可以复制这段字,去百度一下 "仿微信打开网页的进度条效果",你会看到有很多类似的文章,不过他们有个共同点,就是实 ...
- android仿微信 进度条,Android开发之模仿微信打开网页的进度条效果(高仿)
一,为什么说是真正的高仿? 阐述这个问题前,先说下之前网上的,各位可以复制这段字,去百度一下 "仿微信打开网页的进度条效果" ,你会看到有很多类似的文章,不过他们有个共同点,就是 ...
- H5版仿制微信跳一跳小游戏,网页版仿微信跳一跳小游戏源码,实现了跳一跳的基本核心功能
H5版仿制微信跳一跳小游戏,网页版仿微信跳一跳小游戏源码,实现了跳一跳的基本核心功能 完整代码下载地址:H5版仿制微信跳一跳小游戏,网页版仿微信跳一跳小游戏源码 运行截图 Project setup ...
- 关于Mybatis的insert方法返回值(将返回值受影响条数改为插入后的自增主键id)
今天做ssm项目的时候有一个这样的需求--我借阅一本书然后生成一条借阅记录(借阅记录的主键是递增的"borrowNum"),然后将这条记录的主键返回,在往上查阅资料后知道,只要在对 ...
- Android侧滑返回分析和实现(不高仿微信)
项目地址:SLWidget/SwipeBack Demo体验:SLWidget(1.5MB) 侧滑 屏幕旋转 窗口模式 废话 不久前淘汰了用了三年多的iPhone6Plus,换了部三星S9+.流畅的吃 ...
- 安卓开发仿微信图片拖拽_Android 仿微信朋友圈发表图片拖拽和删除功能
朋友圈实现原理 我们使用 Android Device Monitor 来分析朋友圈发布图片的界面实现原理.如果需要分析其他应用的界面实现也是采用这种方法哦. 打开 Android Device Mo ...
- android加载h5页面加进度条,使用Android仿微信加载H5页面的进度条
这篇文章主要为大家详细介绍了Android仿微信加载H5页面进度条,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 前言 Android中WebView打卡前端页面时受到网路环境,页面内容大小的影响 ...
- php 随机钱数,PHP 仿微信红包金额随机
博主寒冰最近闲来无事.就想研究一下微信红包的金额随机算法.早在微信红包刚出来的时候就研究过.始终不得要领.后来,通过查阅诸多资料.听说要实现"正态分布".这个理论的东西不想深挖.恰 ...
- 安卓开发仿微信图片拖拽_Android仿微信朋友圈图片浏览器(支持图片手势缩放,拖动)...
[实例简介] Android仿微信朋友圈图片浏览器(支持图片手势缩放,拖动) [实例截图] [核心代码] ImageDemo-2014-02-18 └── ImageDemo-2014-02-18 ├ ...
最新文章
- python3 json模块操作
- gets scanf以及缓冲区域的问题
- 【直播回放】60分钟讲解深度学习中的数据爬虫和标注
- 弹出确定_Redmi K30 Pro再剧透:弹出式全面屏,没有高刷
- SpringMVC 集成 mybatisPlus
- 被低估的“败家爷们”
- macos模拟器_苹果芯补完计划,iOS终将回归mac OS?
- (转)Inno Setup入门(十七)——Inno Setup类参考(3)
- Oracle将数据库中的表数据导入到另一个数据库中
- matlab工具箱作用简介,Matlab各工具箱功能简介(部分)
- Android水平仪实训报告,测量实训报告范文3篇
- QQ快速登录协议分析
- Python爬取链家北京租房房价|保存为csv格式文件
- 用计算机术语写毕业寄语,大学毕业寄语(精选50句)
- 中国云计算市场排名_中国云计算市场排名第一
- 修改SrollView嵌套下的整个layout背景色
- sht20 python_SHT20 IIC 寄存器概述
- 如何让XP系统能够访问Https
- Introducing Swift(Swift介绍及其API)
- 2018安防行业发展趋势
热门文章
- Android中由IP地址查询经纬度坐标的实例
- Python计算工具
- python爬虫--xpath模块简介
- Json转换利器Gson之实例一-简单对象转化和带泛型的List转化
- 人类的立体视觉与3D拍摄原理
- 学计算机类专业要什么牌子笔记本,请问学计算机专业的大学生买什么牌子的笔记本比较合适...
- linux+取消磁盘阵列,【图文教程】Hetzner独立服务器设置/配置/取消Raid磁盘阵列...
- js返回上一页并刷新的方法
- 新场计算机培训,赢在职新场经典实用课件《创造培训奇迹--ttt》讲义(共90.ppt
- 华安证券分析报告(0607)