Fragment 实现底部导航栏的简单切换

本文记录了作者初次尝试开发Android App的过程,目标是实现底部导航栏的点击切换。首先,作者布置了页面布局,然后为每个导航项创建了对应的Fragment,并编写了布局文件和Fragment类。最后实现了按钮点击事件,成功加载不同页面。
摘要由CSDN通过智能技术生成

第一个Android App:
一直想入android这个坑,但一直因为各种原因拖到了现在,今天终于下定决心迈出了第一步。由于公司一直没有android的项目。所以也没有现成的设计和切图,这对于一个刚入坑的人来说真的挺痛苦的,后来实在没办法,就想到了我平时看小说的软件。经历各种办法终于从apk中拿到了切图。下面就开始吧,走起!

目标:
这里写图片描述
不要想多,今天只是实现底部导航栏的点击切换。

1. 首先将页面的布局写好,这里不多说了。直接上代码。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </FrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="@drawable/home_bg_shape" >

        <RelativeLayout
            android:id="@+id/bookshelf_layout"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/home_bookshelf_image"
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:layout_gravity="center_horizontal"
                    android:src="@drawable/icon_home_tab_bookshelf_n" />

                <TextView
                    android:id="@+id/home_bookshelf_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:text="@string/bookshelf"
                    android:textColor="#82858b" />
            </LinearLayout>
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/searchbook_layout"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/home_searchbook_image"
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:layout_gravity="center_horizontal"
                    android:src="@drawable/icon_home_tab_searchbook_n" />

                <TextView
                    android:id="@+id/searchbook_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:text="@string/free"
                    android:textColor="#82858b" />
            </LinearLayout>
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/bookstore_layout"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/home_bookstore_image"
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:layout_gravity="center_horizontal"
                    android:src="@drawable/icon_home_tab_bookstore_n" />

                <TextView
                    android:id="@+id/bookstore_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:text="@string/bookstore"
                    android:textColor="#82858b" />
            </
  • 6
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值