Android开发--自定义动态导航栏的实现

Android开发–自定义动态导航栏的实现

最近自己用2周的时间和队友零基础尝试开发了一个简单的安卓应用,自己完成了前端和后台的编写,现在把在开发过程中遇到的知识点整理一下,最开始的是导航栏的实现


  1. 内容概括

    1. 结构组成
      设计App的时候准备以四个模块来完成App的设计,因此,在一开始的界面设计了一个MainActivity和4个Fragment来实现模块之间的切换,这里方便学习,已将部分代码省略,注重于动态导航栏的实现

      App导航栏效果展示 这里可以看到背景变化的导航栏以及自定义图标:

      这里写图片描述

      这里写图片描述

    2. 设计思路

      1. 新建4个Fragment对应的对象

      2. 定义一个FragmentManager对象管理器来对Fragment对象进行管理

      3. 自定义函数hideFragments(FragmentTransaction fragmentTransaction)来实现对当前的Fragment隐藏的功能

      4. 自定义函数setChioceItem(int index)调用hideFragments(FragmentTransaction fragmentTransaction)FragmentTransaction的提交实现Fragment之间的转换

      5. 实际开发中,为了让我们的导航栏更加的精美以及实现动态切换效果,特地引入了一个外接控件AHBottomNavigationItem来代替Button等常规控件

      6. 设置控件AHBottomNavigationItem的点击响应的事件来实现界面的切换

  2. 代码实现

    1. xml文件的构成

      <?xml version="1.0" encoding="utf-8"?>
      <android.support.design.widget.CoordinatorLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/color_tab_1">
      
      
          <ScrollView
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
      
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="1"
                  android:orientation="vertical">
      
                  <!--2. 存放四个Fragment-->
                  <FrameLayout
                      android:id="@+id/content"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:background="@color/white"></FrameLayout>
      
              <TextView
                  android:layout_marginTop="45dp"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  />
              </LinearLayout>
      
      
          </ScrollView>
      
          <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
              android:id="@+id/bottom_navigation"
              android:layout_width
  • 4
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值