Android底部菜单栏 仿微博效果
实现方式一:通过TabWidget实现
这种方式主要是在布局中将TabWidget标签嵌套在RelativeLayout中,并且在TabWidget标签中中设置 android:layout_alignParentBottom="true"
另外,下划线和选项卡之间的线去除的方法时在TabWidget标签中设置属性android:tabStripEnabled="false"
xml代码:
xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
>FrameLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:tabStripEnabled="false"
android:background="#6E6E6E"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>TabWidget>
RelativeLayout>
TabHost>
实现代码:
package com.loulijun.demo1;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class Demo1Activity extends TabActivity {
/** Called when the activity is first created. */
private TabHost tabhost;
private Intent intent1, intent2, intent3, intent4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabhost = getTabHost();
intent1 = new Intent(Demo1Activity.this, One.class);
tabhost.addTab(tabhost.newTabSpec("one")
.setIndicator("电话",getResources().getDrawable(android.R.drawable.ic_menu_call))
.setContent(intent1));
intent2 = new Intent(Demo1Activity.this, Two.class);
tabhost.addTab(tabhost.newTabSpec("two")
.setIndicator("相机",getResources().getDrawable(android.R.drawable.ic_menu_camera))
.setContent(intent2));
intent3 = new Intent(Demo1Activity.this, Three.class);
tabhost.addTab(tabhost.newTabSpec("three")
.setIndicator("分享",getResources().getDrawable(android.R.drawable.ic_menu_share))
.setContent(intent3));
intent4 = new Intent(Demo1Activity.this, Four.class);
tabhost.addTab(tabhost.newTabSpec("four")
.setIndicator("更多",getResources().getDrawable(android.R.drawable.ic_menu_more))
.setContent(intent4));
}
}
运行图:
实现方式二:隐藏TabWidget,通过RadioGroup和RadioButton实现底部菜单栏
这种方式更漂亮,也更灵活,网上基本用的是这种方式,通过setCurrentTabByTag来切换不同的选项卡
main.xml:
xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_weight="1.0"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:visibility="gone"/>
<RadioGroup
android:id="@+id/main_tab"
android:background="@drawable/maintab_toolbar_bg"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_gravity="bottom">
<RadioButton
android:layout_marginTop="2.0dip"
android:text="@string/main_home"
android:drawableTop="@drawable/icon_1_n"
android:id="@+id/radio_button0"
style="@style/main_tab_bottom"/>
<RadioButton
android:layout_marginTop="2.0dip"
android:text="@string/main_news"
android:drawableTop="@drawable/icon_2_n"
android:id="@+id/radio_button1"
style="@style/main_tab_bottom"/>
<RadioButton
android:layout_marginTop="2.0dip"
android:text="@string/main_my_info"
android:drawableTop="@drawable/icon_3_n"
android:id="@+id/radio_button2"
style="@style/main_tab_bottom"/>
<RadioButton
android:layout_marginTop="2.0dip"
android:text="@string/menu_search"
android:drawableTop="@drawable/icon_4_n"
android:id="@+id/radio_button3"
style="@style/main_tab_bottom"/>
<RadioButton
android:layout_marginTop="2.0dip"
android:text="@string/more"
android:drawableTop="@drawable/icon_5_n"
android:id="@+id/radio_button4"
style="@style/main_tab_bottom"/>
RadioGroup>
LinearLayout>
TabHost>
drawable/home_btn_bg.xml:切换时的效果:
xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/home_btn_bg_s" />
<item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/home_btn_bg_s" />
<item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/home_btn_bg_d" />
<item android:drawable="@drawable/transparent" />
selector>
string/dimens.xml 尺寸文件:
xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="bottom_tab_padding_drawable">2.0dipdimen>
<dimen name="bottom_tab_padding_up">5.0dipdimen>
<dimen name="bottom_tab_font_size">10.0dipdimen>
resources>
string/drawables.xml 设置为透明:
xml version="1.0" encoding="utf-8"?>
<resources>
<item type="drawable" name="transparent">#00000000item>
resources>
string/styles.xml 样式文件:
xml version="1.0" encoding="utf-8"?>
<resources>
<style name="main_tab_bottom">
<item name="android:textSize">@dimen/bottom_tab_font_sizeitem>
<item name="android:textColor">#ffffffffitem>
<item name="android:ellipsize">marqueeitem>
<item name="android:gravity">center_horizontalitem>
<item name="android:background">@drawable/home_btn_bgitem>
<item name="android:paddingTop">@dimen/bottom_tab_padding_upitem>
<item name="android:layout_width">fill_parentitem>
<item name="android:layout_height">wrap_contentitem>
<item name="android:button">@nullitem>
<item name="android:singleLine">trueitem>
<item name="android:drawablePadding">@dimen/bottom_tab_padding_drawableitem>
<item name="android:layout_weight">1.0item>
style>
resources>
代码:
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class MainTabActivity extends TabActivity implements OnCheckedChangeListener{
private RadioGroup mainTab;
private TabHost tabhost;
private Intent iHome;
private Intent iNews;
private Intent iInfo;
private Intent iSearch;
private Intent iMore;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mainTab=(RadioGroup)findViewById(R.id.main_tab);
mainTab.setOnCheckedChangeListener(this);
tabhost = getTabHost();
iHome = new Intent(this, HomeActivity.class);
tabhost.addTab(tabhost.newTabSpec("iHome")
.setIndicator(getResources().getString(R.string.main_home), getResources().getDrawable(R.drawable.icon_1_n))
.setContent(iHome));
iNews = new Intent(this, NewsActivity.class);
tabhost.addTab(tabhost.newTabSpec("iNews")
.setIndicator(getResources().getString(R.string.main_news), getResources().getDrawable(R.drawable.icon_2_n))
.setContent(iNews));
iInfo = new Intent(this, MyInfoActivity.class);
tabhost.addTab(tabhost.newTabSpec("iInfo")
.setIndicator(getResources().getString(R.string.main_my_info), getResources().getDrawable(R.drawable.icon_3_n))
.setContent(iInfo));
iSearch = new Intent(this,SearchActivity.class);
tabhost.addTab(tabhost.newTabSpec("iSearch")
.setIndicator(getResources().getString(R.string.menu_search), getResources().getDrawable(R.drawable.icon_4_n))
.setContent(iSearch));
iMore = new Intent(this, MoreActivity.class);
tabhost.addTab(tabhost.newTabSpec("iMore")
.setIndicator(getResources().getString(R.string.more), getResources().getDrawable(R.drawable.icon_5_n))
.setContent(iMore));
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId){
case R.id.radio_button0:
this.tabhost.setCurrentTabByTag("iHome");
break;
case R.id.radio_button1:
this.tabhost.setCurrentTabByTag("iNews");
break;
case R.id.radio_button2:
this.tabhost.setCurrentTabByTag("iInfo");
break;
case R.id.radio_button3:
this.tabhost.setCurrentTabByTag("iSearch");
break;
case R.id.radio_button4:
this.tabhost.setCurrentTabByTag("iMore");
break;
}
}
}
运行图:
转载于:https://www.cnblogs.com/xieyuan/archive/2013/06/11/3787414.html
Android底部菜单栏 仿微博效果相关推荐
- Android实现动态贴纸,Android开发之仿微博贴纸效果实现——进阶篇
上个月写了一篇<Android开发之仿微博贴纸效果实现--基础篇>,文章中提到还有一篇进阶篇要写,很早就想动笔了,因中途去维护了开源库<高仿微信图片选择器2.0版本>,导致耽搁 ...
- android底部菜单栏demo
上一个项目已经做完了,这周基本上没事,所以整理了下以前的项目,想把一些通用的部分封装起来,这样以后遇到相似的项目就不用重复发明轮子了,也节省了开发效率.今天把demo贴出来一是方便以后自己查询,二是希 ...
- android radiogroup 底部菜单,Android底部菜单栏(RadioGroup+Fragment)美化
众所周知,android的底部菜单栏太重要,平时项目一般都是需要用到的,但是网上关于这方面的demo做得太丑了,实在惨不忍睹,所以这里便用RadioGroup+Fragment的方式写了一个,顺便美化 ...
- Android底部菜单栏(图片+文字)
虽然网上有很多底部菜单栏的实现方式,但是实现方式各种各样,很多也不符合自己的口味,所以还是总结下底部菜单栏的实现方式,以便以后方便查询使用 实现方式一:通过TabWidget实现 这种方式主要是在布局 ...
- Android底部菜单栏、Android沉浸式状态栏(顶部状态栏修改颜色)、自定义标题栏
0.简介: 没有使用TabHost切换,而是变成FragmentActivity替换Fragment:沉浸式引用的git上面的jar包. 先看图片 1.底部导航栏 核心代码 <span styl ...
- android 自定义菜单栏,GitHub - earthWo/AndroidBottomNavigation: android 底部菜单栏,自定义样式,自定义菜单数量,添加滚动动画和水波纹动画...
AndroidBottomNavigation 截图 使用方法 gradle: compile 'com.whitelife.library:library:1.0.1' maven: com.whi ...
- 【Android UI设计与开发】第09期:底部菜单栏(四)Fragment+PopupWindow仿QQ空间最新版底部菜单栏
转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/9023451 在今天的这篇文章当中,我依然会以实战加理论结合 ...
- Android仿微信底部菜单栏+顶部菜单栏(附源码)
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 本文要实现仿微信微信底部菜单栏+顶部菜单栏,采用ViewPage来做,每一个page对应一个X ...
- Android仿微信底部菜单栏+今日头条顶部导航栏
背景 Android应用几乎都会用到底部菜单栏,在Material Design还没有出来之前,TabHost等技术一直占主流,现在Google新sdk中提供了TabLayout类可以便捷的做出底部菜 ...
最新文章
- 如何初始化一个定长ListT
- java rmi 还有用吗_java rmi使用后的感想
- linux下解除端口占用
- BZOJ3083: 遥远的国度(树链剖分)
- Promise.all捕获错误
- flask mysql 配置文件_flask配置文件的几种方法
- python如何将图片打包进exe里_用python将图片切分为九宫格 并打包成exe可执行文件(附源码)...
- python语言中文怎么读-python中文读什么
- modis数据产品行列号以及数据行列号
- 批量梯度下降(BGD)、小批量梯度下降(mini-BGD)、随机梯度下降(SGD)优缺点比较
- 2014年二级c语言题库,全国计算机二级c语言题库试题
- 算法精解 c语言 源码,算法精解七(C语言版)
- python正交表结果生成
- Java基础(七) 房屋出租系统
- 沃达丰高管:澳大利亚将于2020年迎来5G
- Mac开发-公证流程记录Notarization-附带脚本
- 网络电视测试软件,电视屏幕检测(三款智能电视屏幕检测软件)
- vs全项目搜索关键词
- vue el-table的合并单元格与拆分单元格
- 设计中的设计-设计的意义
热门文章
- 计算机知识的更新速度,笔记本电脑硬盘如何升级?要容量还是速度?这些知识你需要学会...
- java 并发实例_java一些常用并发工具示例
- Modelsim仿真时不能编译`include文件解决办法
- linux中cc和S的区别,为什么在linux命令(iostat)中每秒读取(r/s)一直为零?
- 没有找到mysql。sock_linux系统安装mysql数据库
- ARM7还是ARM9?uCOS还是Linux?
- python SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: trunca
- 安装debian总结以及编译linux内核
- [TJOI2019]甲苯先生的滚榜——非旋转treap
- 放大倍数超5万倍的Memcached DDoS反射攻击,怎么破?