导航:首页 > 操作系统 > android底部导航栏实现

android底部导航栏实现

发布时间:2022-12-26 23:52:57

android使用fragment实现底部导航栏切换界面

源码链接

效果图

创建bottom_layout.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:gravity="center">

<ImageView

        android:layout_width="36dp"

        android:layout_height="36dp"

        android:id="@+id/bottom_icon"

        />

<TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textColor="#565656"

        android:textSize="10sp"

        android:id="@+id/bottom_text" />

public void setNormalImage(int normalIcon){

this.normalIcon = normalIcon;

    ivIcon.setImageResource(normalIcon);

}

public void setFocusedImage(int focusedIcon){

this.focusedIcon = focusedIcon;

}

public void setTvText(String text){

tvText.setText(text);

}

public void setFocused(boolean isFocused){

this.isFocused = isFocused;

    if(isFocused){

ivIcon.setImageResource(focusedIcon);

        tvText.setTextColor(Color.parseColor("#02b5bc"));

    }else{

ivIcon.setImageResource(normalIcon);

        tvText.setTextColor(Color.BLACK);

    }

}

<FrameLayout

    android:id="@+id/frameLayout_container"

    android:layout_width="match_parent"

    android:layout_height="0dp"

    android:layout_weight="11"

    >

</FrameLayout>

四个如下

<com.example.qiaolulu.qiaofragment.BottomLayout

    android:id="@+id/square"

    android:layout_width="0dp"

    android:layout_height="wrap_content"

    android:layout_weight="1">

</com.example.qiaolulu.qiaofragment.BottomLayout>

public class Babyextends Fragment{

@Nullable

@Override

    public ViewonCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

//加载你设计要显示的界面

View view = inflater.inflate(R.layout.baby,null);

        return view;

    }

}

fragmentManager = getSupportFragmentManager();

FragmentTransaction transaction =fragmentManager.beginTransaction();

firstPage =new FirstPage();

transaction.add(R.id.frameLayout_container,firstPage);

transaction.commit();

㈡ android 判断有没有底部导航栏

很多android应用底部都有一个底部导航栏,方便用户在使用过程中随意切换。目前常用的做法有三种:一种是使用自定义tabHost,一种是使用activityGroup,一种是结合FrameLayout实现。笔者再做了多款应用后,为了节约开发周期,封装了一个抽象类,只要三步便可完成底部栏的生成及不同页面的调用。
public class extends ActivityCollection {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setBottomTabBackground(resId);// 设置底部导航背景图
@Override
protected boolean isShowWindowFeature() {
return true;//设置是否显示title;
@Override
protected ListIndicatorInfo> setDrawableCollections() {
ListIndicatorInfo> IndicatorInfos = new ArrayListIndicatorInfo>();
IndicatorInfo indicatorInfo_1 = new IndicatorInfo(R.drawable.baby1,
R.drawable.baby1_s, R.string.baby1, 12, Color.WHITE,
new Intent(.this,
Activity01.class));
IndicatorInfo indicatorInfo_2 = new IndicatorInfo(R.drawable.baby2,
R.drawable.baby2_s, R.string.baby2, 12, Color.WHITE,
new Intent(.this,
Activity02.class));
IndicatorInfo indicatorInfo_3 = new IndicatorInfo(R.drawable.baby3,
R.drawable.baby3_s, R.string.baby3, 12, Color.WHITE,
new Intent(.this,
Activity03.class));
IndicatorInfo indicatorInfo_4 = new IndicatorInfo(R.drawable.baby4,
R.drawable.baby4_s, R.string.baby4, 12, Color.WHITE,
new Intent(.this,
Activity04.class));
IndicatorInfos.add(indicatorInfo_1);
IndicatorInfos.add(indicatorInfo_2);
IndicatorInfos.add(indicatorInfo_3);
IndicatorInfos.add(indicatorInfo_4);
return IndicatorInfos;

第一步:导入jar包;
第二步:让你的homeactivity 继承ActivityCollection类;
第三步:将你的图片资源及跳转intent放入list中,设置可选项;
雏形就形成啦!

㈢ 超简单,几行代码搞定Android底部导航栏

咳咳,答应过年增加新功能的,没想到拖到现在,延迟了一个来月,尴尬,尴尬
那个,我们先忽略这尴尬的事情吧,进入正题才是最重要滴

老规矩,先上效果图:

跟原来的图有个很明显的区别,你们也一定都发现了,对不对。那么显眼的小红点,一定都看到了吧。

当然除了这个,还增加了一项功能,虽然不是很明显,但相信也有小伙伴发现了吧,截图的这俩手机屏幕明显大小不同,但是底部导航栏的大小还是相差不大滴。

是的,你们没有看多,这次不仅增加了小红点功能,还增加了底部导航栏的适配,你没有听错,以后底部导航栏也不用那些dp、sp了,都按照UI妹子们标注的px来就可以了,再也不用为了底部导航栏去跟UI妹子解释啥叫dp了。

好了,效果图展示完了,现在该进入枯燥的使用介绍了。

由于这次改动有点大,所以,先介绍下上个稳定版本的用法,到底是用最新的,还是用原来的,就看各位小伙伴的意愿了

上个稳定版本是1.1.3的,引用方式如下
compile 'com.hjm:BottomTabBar:1.1.3'

具体用法如下(备注都加好了,我也就不多废话了):

最新版本是1.2.2的,引用方式如下
compile 'com.hjm:BottomTabBar:1.2.2'

其实1.2.0与1.1.3区别并不大,只有4点改动:

现在默认的,分割线高度都是设置的1个像素。这里以后也固定都用这个默认的高度了,不再对外提供修改的方法。

这就是新增加的适配了,多的也不说了,你们都懂的

标准尺寸,就是UI妹子给你提供的效果图的屏幕尺寸,只要在init()方法里添加上标准尺寸,你就可以放肆的使用px了

这个方法就是控制小红点显示的方法了,index就是需要显示或者隐藏小红点的TabItem,isShow是一个boolean类型的参数,他是控制小红点是否显示的,如果为true,就会显示小红点;如果为false,就会隐藏小红点

1.2.2版本新增了两个方法

介绍到这里,超简单的底部导航栏,第二阶段就可以告一段落了。以后还会持续优化,完善的。
第三阶段我打算封装一下有中间凸起的底部导航栏,这个功能我本地已经做了,但是封装进去的时候,封装的不理想,这次就没有上线,留作下次了。

最后,再上个 GitHub 地址

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

在一个普通类中(非继承Activity等),点击截界面上某一按钮隐藏底部导航栏(Back、Home、多任务切换),再次点击让其出现;
实现:隐藏view.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| Utils.SYSTEM_UI_FLAG_IMMERSIVE);
显示view.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
而且加了界面touch监听,在隐藏模式下,单击屏幕不让导航栏出现;

阅读全文

与android底部导航栏实现相关的资料

热点内容
单片机的原理概述 浏览:506
火控pdf 浏览:267
如何复制云服务器centos环境 浏览:984
债权pdf 浏览:299
红色番字的app怎么下载 浏览:876
云服务器流程教课 浏览:702
中国农业银行app怎么没有网 浏览:997
几率表算法 浏览:902
程序员理工科 浏览:708
企业邮箱登录收件服务器地址 浏览:558
计算机思维与算法设计的重要性 浏览:664
linux刷新磁盘命令 浏览:76
我的世界如何查看服务器种子pc 浏览:284
linuxlamp编译安装 浏览:609
枚举算法ppt 浏览:184
cmd查看进程命令 浏览:956
手机内怎么删除APP 浏览:834
鱼群和鸟群算法区别 浏览:93
pdf尺寸设置 浏览:211
android访问本地服务器 浏览:512