android开发时如何去掉mui底部导航栏的导航栏?

&&&&android底部凸起导航菜单
android底部凸起导航菜单
Android底部导航凸起菜单,利用的是FrameLayout实现的,效果和RadioGroup一样,同样有选中高亮的效果
若举报审核通过,可奖励20下载分
被举报人:
shepherd1st
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
移动开发下载排行zhf 的BLOG
用户名:zhf
文章数:49
评论数:92
访问量:370068
注册日期:
阅读量:5863
阅读量:12276
阅读量:310451
阅读量:1026049
51CTO推荐博文
今天,我将总结一下Android应用中大家经常见到的底部导航栏的几种实现!一。TabHost + RadioGroup实现方式 在我们平时开发过程中使用的TabHost是在上方,这里我们简单修改了一下&TabHost&的布局,让叶片放到了底部。main.xml&?xml version="1.0" encoding="utf-8"?&
&TabHost xmlns:android="/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" &
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" &
&TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" /&
&FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0" /&
&RadioGroup
android:id="@+id/radioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/bar"
android:gravity="center_vertical"
android:orientation="horizontal" &
&RadioButton
android:id="@+id/rd_home"
style="@style/main_btn_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/home_icon"
android:text="主页" /&
&RadioButton
android:id="@+id/rd_wt"
style="@style/main_btn_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/wb_icon_write_n"
android:text="发表" /&
&RadioButton
android:id="@+id/rd_msg"
style="@style/main_btn_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/msg_icon"
android:text="信息" /&
&RadioButton
android:id="@+id/rd_more"
style="@style/main_btn_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/more_icon"
android:text="更多" /&
&/RadioGroup&
&/LinearLayout&
&/TabHost&styles.xml&style name="main_btn_style"&
&item name="android:button"&@null&/item&
&item name="android:textSize"&10dp&/item&
&item name="android:textColor"&#ffffff&/item&
&item name="android:gravity"&center_horizontal&/item&
&item name="android:drawablePadding"&4dp&/item&
&item name="android:layout_weight"&1.0&/item&
&item name="android:background"&@drawable/main_btn_bg_d&/item&
&/style&main_btn_bg_d.xml&?xml version="1.0" encoding="utf-8"?&
&selector xmlns:android="/apk/res/android"&
&item android:drawable="@drawable/main_btn_bg" android:state_enabled="true" android:state_pressed="true"&&/item&
&item android:drawable="@drawable/main_btn_bg" android:state_checked="true" android:state_enabled="true"&&/item&
&/selector&这里需要注意的是:
1.main.xml中:TabWidget的id必须是@android:id/tabs,FrameLayout的id必须是 @android:id/tabcontent。
2.把TabWidget的Visibility设置成了gone!也就是默认难看的风格不见了:650) this.width=650;" src="/cnblogs_com/over140/1-3-1_2.jpg" height="34" width="155" style="border:0color:#4b4b4b;font-family:verdana, geneva, arial, helvetica, sans-font-size:13line-height:19background-color:#" alt="_2.jpg" />,取而代之的是5个带风格的单选按钮.MainActivity类package com.zhf.android_
import android.app.TabA
import android.content.I
import android.os.B
import android.widget.RadioG
import android.widget.RadioGroup.OnCheckedChangeL
import android.widget.TabH
import android.widget.TabHost.TabS
public class MainActivity extends TabActivity {
private TabHost tabH
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = this.getTabHost();
TabSpec homeSpec = tabHost.newTabSpec("home").setIndicator("home").setContent(new Intent(this,HomeActivity.class));
TabSpec writeSpec = tabHost.newTabSpec("write").setIndicator("write").setContent(new Intent(this,WriteActivity.class));
TabSpec msgSpec = tabHost.newTabSpec("msg").setIndicator("msg").setContent(new Intent(this,MsgActivity.class));
TabSpec moreSpec = tabHost.newTabSpec("more").setIndicator("more").setContent(new Intent(this,MoreActivity.class));
tabHost.addTab(homeSpec);
tabHost.addTab(writeSpec);
tabHost.addTab(msgSpec);
tabHost.addTab(moreSpec);
RadioGroup rg = (RadioGroup) this.findViewById(R.id.radioGroup);
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.rd_home:
tabHost.setCurrentTabByTag("home");
case R.id.rd_wt:
tabHost.setCurrentTabByTag("write");
case R.id.rd_msg:
tabHost.setCurrentTabByTag("msg");
case R.id.rd_more:
tabHost.setCurrentTabByTag("more");
}注: 1.由于TabWidget被隐藏,所以相关的事件也会无效,这里取巧用RadioGroup与RadioButton的特性来处理切换,然后监听事件调用setCurrentTabByTag来切换Activity。 2.注意即使TabWidget被隐藏,也要为其设置indicator,否则会保持。效果图:(点击底部就可以实现切换不同的Activity的操作了,这里需要注意的一点是,切换底部菜单时不会重新调用onCreate()方法的!!)二.底部回调接口实现(使用Fragment)--- 重要!
这种方式使用了最新的Fragment,采用了底部导航栏回调接口的方法,来切换底部菜单,并且每次切换回重新调用onCreate()方法!!main.xml:&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" &
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:orientation="vertical" &
&RelativeLayout
android:id="@+id/main_title_RelativeLayout"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/fragment_bottom_normal"
android:orientation="horizontal" &
android:id="@+id/main_title_TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="主页"
android:textColor="@android:color/white"
android:textSize="24sp" /&
&/RelativeLayout&
&FrameLayout
android:id="@+id/main_detail_FrameLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff" &
&/FrameLayout&
&/LinearLayout&
android:id="@+id/bottom_fragment"
android:name="com.zhf.frameworkdemo02.fragments.BottomFragment"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" /&
&/LinearLayout&这里由于我们底部菜单我们采用了fragment,所以布局里面要留出位置!BottomFragment类:package com.zhf.frameworkdemo02.
import com.zhf.frameworkdemo02.R;
import android.app.A
import android.os.B
import android.support.v4.app.F
import android.view.LayoutI
import android.view.V
import android.view.ViewG
import android.widget.RadioG
import android.widget.RadioGroup.OnCheckedChangeL
* 页面底部导航栏
* @author ZHF
public class BottomFragment extends Fragment {
//默认回调接口实现类的对象
private Callbacks callbacks = defaultC
/** Fragment和Activity建立关联的时候调用 **/
public void onAttach(Activity activity) {
super.onAttach(activity);
//当前类是否实现了底部导航栏点击事件回调接口
if(!(activity instanceof Callbacks)) {
throw new IllegalStateException("Activity must implements fragment's callbacks !");
callbacks = (Callbacks)
/** 为Fragment加载布局时调用 **/
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
RadioGroup radioGroup = (RadioGroup) inflater.inflate(R.layout.fragment_bottom, container, false);
//绑定监听器
radioGroup.setOnCheckedChangeListener(changeListener);
return radioG
/**RadioGroup监听器**/
private OnCheckedChangeListener changeListener = new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
System.out.println(checkedId);
callbacks.onItemSelected(checkedId); //调用接口中方法
public interface Callbacks{
/**导航栏回调接口**/
public void onItemSelected(int item);
/**默认回调实现类的对象**/
private static Callbacks defaultCallbacks = new Callbacks() {
public void onItemSelected(int item) {
//什么都不干
/**Fragment和Activity解除关联的时候调用**/
public void onDetach() {
super.onDetach();
callbacks = defaultC
}底部菜单布局fragment_bottom.xml&?xml version="1.0" encoding="utf-8"?&
&RadioGroup xmlns:android="/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" &
&RadioButton
android:id="@+id/fragment_bottom_home"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/fragment_bottom_selector"
android:button="@null"
android:drawableTop="@drawable/main_readiobutton_home"
android:gravity="center"
android:text="@string/home"
android:textColor="@color/white"
android:textSize="12sp" /&
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="@color/white" /&
&RadioButton
android:id="@+id/fragment_bottom_order"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/fragment_bottom_selector"
android:button="@null"
android:drawableTop="@drawable/main_readiobutton_order"
android:gravity="center"
android:text="@string/order"
android:textColor="@color/white"
android:textSize="12sp" /&
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="@color/white"
&RadioButton
android:id="@+id/fragment_bottom_notice"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/fragment_bottom_selector"
android:button="@null"
android:drawableTop="@drawable/main_readiobutton_notice"
android:gravity="center"
android:text="@string/notice"
android:textColor="@color/white"
android:textSize="12sp" /&
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="@color/white" /&
&RadioButton
android:id="@+id/fragment_bottom_more"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/fragment_bottom_selector"
android:button="@null"
android:drawablePadding="3dip"
android:drawableTop="@drawable/main_readiobutton_more"
android:gravity="center"
android:text="@string/more"
android:textColor="@color/white"
android:textSize="12sp" /&
&/RadioGroup&这里我们定义了一个框架类:GeneralFragment(所有的fragment界面都需继承它)package com.zhf.frameworkdemo02.
import java.io.S
import com.zhf.frameworkdemo02.R;
import com.zhf.frameworkdemo02.view.OrderV
import com.zhf.frameworkdemo02.view.HomeV
import com.zhf.frameworkdemo02.view.MoreV
import com.zhf.frameworkdemo02.view.NoticeV
import android.os.B
import android.support.v4.app.F
import android.view.LayoutI
import android.view.V
import android.view.ViewG
import android.widget.TextV
* 框架类,抽象公共方法
* @author ZHF
public class GeneralFragment extends Fragment implements Serializable{
private static final long serialVersionUID = 1L;
//用于区分底部菜单项
protected static View main_title_RelativeL //标题栏
protected final static String key = "Bundle";
//跳转值传递key的名称
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(getArguments() != null) {
//根据接收子类传来的arguments判断item的哪一项
if(getArguments().containsKey(MainFragment.Item)) {
item = getArguments().getInt(MainFragment.Item);
/**为Fragment加载布局时调用 **/
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_general, container, false);
GeneralFragment fragment =
switch(item) {
case R.id.fragment_bottom_home:
//初始化主页
fragment = new HomeView();
case R.id.fragment_bottom_order:
fragment = new OrderView();
//初始化订单
case R.id.fragment_bottom_notice:
fragment = new NoticeView();
//初始化公告
case R.id.fragment_bottom_more:
fragment = new MoreView();
//初始化更多
if(fragment != null) {
//更换mainView中间的内容(home,msg,at,more)
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.general_fragment, fragment).commit();
main_title_RelativeLayout =
((View) container.getParent()).findViewById(R.id.main_title_RelativeLayout);
//将生成的view返回
/**设置标题**/
protected void setTitle(Object title) {
if(main_title_RelativeLayout != null) {
//标题栏中的文字
TextView mTvTitle = (TextView) main_title_RelativeLayout.findViewById(R.id.main_title_TextView);
if(mTvTitle != null) {
if(title instanceof Integer) {
mTvTitle.setText((Integer)title);
} else { //字符类型
mTvTitle.setText((CharSequence)title);
/**页面跳转值传递**/
protected void setBundle(Object... objects) {
Bundle arguments = new Bundle();
arguments.putSerializable(key, objects);
GeneralFragment generalFragment = new GeneralFragment();
generalFragment.setArguments(arguments);
/**获取所传递的值**/
protected Object[] getBundle() {
if(getArguments() != null) {
System.out.println("getBundle");
if(getArguments().containsKey(key)) {
Object[] object = (Object[]) getArguments().getSerializable(key);
/**无参页面跳转**/
protected void toIntent(GeneralFragment generalFragment) {
if(generalFragment != null) {
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.general_fragment, generalFragment).commit();
}程序入口MainFragment:package com.zhf.frameworkdemo02.
import com.zhf.frameworkdemo02.R;
import android.os.B
import android.support.v4.app.FragmentA
import android.support.v4.app.FragmentM
* @author ZHF
public class MainFragment extends FragmentActivity implements BottomFragment.Callbacks {
public final static String Item = "item";
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//初始化默认调用接口中item选中方法
onItemSelected(R.id.fragment_bottom_home);
public void onItemSelected(int item) {
Bundle arguments = new Bundle();
arguments.putInt(Item, item); //将选中的底部radio的Id放进去
GeneralFragment generalFragment = new GeneralFragment();
generalFragment.setArguments(arguments); //设置参数值
//这里根据item的ID进行界面跳转
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().replace(R.id.main_detail_FrameLayout, generalFragment).commit();
}说明:这里我们的每个界面都将采用Fragment,故每个界面需重写onCreateView()package com.zhf.frameworkdemo02.
import android.os.B
import android.view.LayoutI
import android.view.V
import android.view.ViewG
import com.zhf.frameworkdemo02.R;
import com.zhf.frameworkdemo02.fragments.GeneralF
* @author ZHF
public class HomeView extends GeneralFragment{
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
super.setTitle("主页");
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.home, container, false);
}(其他三个略)最终效果图:ok!大功告成!相当实用的!有兴趣的可以学习一下!源码下载:本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)
14:52:13 13:06:48 23:31:30 10:26:26 10:53:25 13:01:09Android使用Fragment实现底部导航栏分析
在做移动开发过程中底部导航栏是十分常见的功能,且市面上见到的做法也有很多种,这篇博文记录一下使用Fragment实现底部导航栏的功能,算是对这几天学习Android做的Demo的一个总结吧。
好久不敲代码,确实生疏不少。现在发现使用博客记录自己平时的学习资料,节省了很多搜集资料的时间,是一个很好的学习方法。
IDE:AS,A 模拟器: 实现的效果,见下图。
为了讲明白这个实现过程,我们贴出来的代码多一写,这样更方便理解 [最后还会放出完整的代码实现] 。看上图的界面做的比较粗糙,但实现过程的骨架都具有了,想要更完美的设计,之后自行完善吧 ^0^。
通过观察上述效果图,发现任意一个选项页面都有三部分组成:
顶部去除ActionBar后的标题栏;中间一个FragmentLayout用来放相应的Fragment;底部一个大的LinearLayout放着四个样式一样的(ImagView + TextView)的小Item。
(1) 完整具体的代码,详见:show_main_lay.xml,通过注释可以看到该布局的三部分组成。
&framelayout android:background="@color/whitesmoke" android:id="@+id/content" android:layout_height="0dp" android:layout_weight="1" android:layout_width="match_parent"&&/framelayout&
附上源码截图吧:
(2) 对于布局的第一部分的顶部标题栏,代码请见:title_layout.xml:
见下截图:
(3) 布局中间的第二部分我们再分别建立4个.xml布局文件,分别命名为:fg1.xml、fg2.xml、fg3.xml、fg4.xml,内容上只更改一下TextView中的文字说明,如第一个页面,改为第二个页面。下面只给出其中一个fg1.xml:
(4) 这里也给出Values目录下的colors.xml内容吧,颜色还是比较完整的但是名字不好记:
那么到这里我们的界面布局就基本完成了!
相应Fragment的实现类
接下来我们需要写四个相应的Fragment的实现类,同样拷贝4份,改用inflate加载Fragment即可。即,包含四个差不多一样的Fragment,分别起名为:FirstFragment.java、SecondFragment.java、ThirdFragment.java、FourthFragment.java。下面主要展示一下FirstFragment.java的具体代码:
package com.example.dm.
import android.os.B
import android.support.v4.app.F
import android.view.LayoutI
import android.view.V
import android.view.ViewG
* Created by dm on 16-3-29.
* 第一个页面
public class FirstFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fg1, container, false);
最重要的MainActivity
各个七零八落的小部件都已经准备到序了,现在只剩下这个主界面实现类把他们融合在一起,实现相应的效果了。MainActivity.java 的编写也很简单,直接看代码和注释就可以了,不多解释额:主要包含几个初始化方法、选中处理、隐藏所有Fragment的方法。详见MainActivity.java:
package com.example.dm.
import android.content.I
import android.os.B
import android.support.v4.app.FragmentA
// 注意这里我们导入的V4的包,不要导成app的包了
import android.support.v4.app.FragmentM
import android.support.v4.app.FragmentT
import android.view.V
import android.widget.FrameL
import android.widget.ImageV
import android.widget.RelativeL
import android.widget.TextV
* 主页面内容
* Created by dm on 16-1-19.
public class MainActivity extends FragmentActivity implements View.OnClickListener {
// 初始化顶部栏显示
private ImageView titleLeftI
private TextView titleTv;
// 定义4个Fragment对象
private FirstFragment fg1;
private SecondFragment fg2;
private ThirdFragment fg3;
private FourthFragment fg4;
// 帧布局对象,用来存放Fragment对象
private FrameLayout frameL
// 定义每个选项中的相关控件
private RelativeLayout firstL
private RelativeLayout secondL
private RelativeLayout thirdL
private RelativeLayout fourthL
private ImageView firstI
private ImageView secondI
private ImageView thirdI
private ImageView fourthI
private TextView firstT
private TextView secondT
private TextView thirdT
private TextView fourthT
// 定义几个颜色
private int whirt = 0xFFFFFFFF;
private int gray = 0xFF7597B3;
private int dark = 0xff000000;
// 定义FragmentManager对象管理器
private FragmentManager fragmentM
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_main_lay);
fragmentManager = getSupportFragmentManager();
initView(); // 初始化界面控件
setChioceItem(0);
// 初始化页面加载时显示第一个选项卡
* 初始化页面
private void initView() {
// 初始化页面标题栏
titleLeftImv = (ImageView) findViewById(R.id.title_imv);
titleLeftImv.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, LoginActivity.class));
titleTv = (TextView) findViewById(R.id.title_text_tv);
titleTv.setText(&首 页&);
// 初始化底部导航栏的控件
firstImage = (ImageView) findViewById(R.id.first_image);
secondImage = (ImageView) findViewById(R.id.second_image);
thirdImage = (ImageView) findViewById(R.id.third_image);
fourthImage = (ImageView) findViewById(R.id.fourth_image);
firstText = (TextView) findViewById(R.id.first_text);
secondText = (TextView) findViewById(R.id.second_text);
thirdText = (TextView) findViewById(R.id.third_text);
fourthText = (TextView) findViewById(R.id.fourth_text);
firstLayout = (RelativeLayout) findViewById(R.id.first_layout);
secondLayout = (RelativeLayout) findViewById(R.id.second_layout);
thirdLayout = (RelativeLayout) findViewById(R.id.third_layout);
fourthLayout = (RelativeLayout) findViewById(R.id.fourth_layout);
firstLayout.setOnClickListener(MainActivity.this);
secondLayout.setOnClickListener(MainActivity.this);
thirdLayout.setOnClickListener(MainActivity.this);
fourthLayout.setOnClickListener(MainActivity.this);
public void onClick(View v) {
switch (v.getId()) {
case R.id.first_layout:
setChioceItem(0);
case R.id.second_layout:
setChioceItem(1);
case R.id.third_layout:
setChioceItem(2);
case R.id.fourth_layout:
setChioceItem(3);
* 设置点击选项卡的事件处理
* @param index 选项卡的标号:0, 1, 2, 3
private void setChioceItem(int index) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
clearChioce(); // 清空, 重置选项, 隐藏所有Fragment
hideFragments(fragmentTransaction);
switch (index) {
firstImage.setImageResource(R.drawable.XXXX); 需要的话自行修改
firstText.setTextColor(dark);
firstLayout.setBackgroundColor(gray);
// 如果fg1为空,则创建一个并添加到界面上
if (fg1 == null) {
fg1 = new FirstFragment();
fragmentTransaction.add(R.id.content, fg1);
// 如果不为空,则直接将它显示出来
fragmentTransaction.show(fg1);
secondImage.setImageResource(R.drawable.XXXX);
secondText.setTextColor(dark);
secondLayout.setBackgroundColor(gray);
if (fg2 == null) {
fg2 = new SecondFragment();
fragmentTransaction.add(R.id.content, fg2);
fragmentTransaction.show(fg2);
thirdImage.setImageResource(R.drawable.XXXX);
thirdText.setTextColor(dark);
thirdLayout.setBackgroundColor(gray);
if (fg3 == null) {
fg3 = new ThirdFragment();
fragmentTransaction.add(R.id.content, fg3);
fragmentTransaction.show(fg3);
fourthImage.setImageResource(R.drawable.XXXX);
fourthText.setTextColor(dark);
fourthLayout.setBackgroundColor(gray);
if (fg4 == null) {
fg4 = new FourthFragment();
fragmentTransaction.add(R.id.content, fg4);
fragmentTransaction.show(fg4);
* 当选中其中一个选项卡时,其他选项卡重置为默认
private void clearChioce() {
firstImage.setImageResource(R.drawable.XXX);
firstText.setTextColor(gray);
firstLayout.setBackgroundColor(whirt);
secondImage.setImageResource(R.drawable.XXX);
secondText.setTextColor(gray);
secondLayout.setBackgroundColor(whirt);
thirdImage.setImageResource(R.drawable.XXX);
thirdText.setTextColor(gray);
thirdLayout.setBackgroundColor(whirt);
fourthImage.setImageResource(R.drawable.XXX);
fourthText.setTextColor(gray);
fourthLayout.setBackgroundColor(whirt);
* 隐藏Fragment
* @param fragmentTransaction
private void hideFragments(FragmentTransaction fragmentTransaction) {
if (fg1 != null) {
fragmentTransaction.hide(fg1);
if (fg2 != null) {
fragmentTransaction.hide(fg2);
if (fg3 != null) {
fragmentTransaction.hide(fg3);
if (fg4 != null) {
fragmentTransaction.hide(fg4);
到这里我们的功能就基本实现了,是不是还挺简单的。
Fragment相关类导入的时候是v4包还是app包!我们这里导入的是V4的包,在代码的注释部分,已经给出说明; 在完整的代码包中,我们还添加了App启动界面及动画、登录界面,这两部分的内容,这里不做具体的说明,之后继续完善。
完整Demo下载地址: 访问密码 39b5
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'

我要回帖

更多关于 安卓底部导航栏 的文章

 

随机推荐