Android中使用Fragment与RadioGroup实现页面布局切换

本文介绍如何在Android应用中利用Fragment和RadioGroup实现页面间的切换。通过创建Titlebar标题栏,定义不同Fragment(CommonFrameFragment, ThirdPartyFragment, CustomFragment, OtherFragment)并结合RadioGroup,实现清晰的界面层级,方便用户操作。" 112584277,9549694,区块链应用:实体经济新动力,"['区块链', '数字经济', '供应链管理', '政府治理', '技术创新']
摘要由CSDN通过智能技术生成

现在的APP主页面界面设计,一般采用的是几个按钮加上不同的Fragment来切换页面,看起来层次很清晰,让用户一目了然,下面就用Fragment和RadioGroup来实现页面之间的切换,界面设计如下图所示:
这里写图片描述

代码如下:

titlebar.xml(Titlebar标题栏)

<?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="50dp"
    android:background="@android:color/holo_blue_light"
    android:gravity="center"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="标题"
        android:textColor="@android:color/white"
        android:textSize="20sp" />
</LinearLayout>

styles.xml

<resources>
    ...
    <style name="bottom_tag_style" >
        <!-- Customize your theme here. -->
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_weight">1</item>
        <item name="android:button">@android:color/transparent</item>
        <item name="android:drawablePadding">3dp</item>
        <item name="android:gravity">center</item>
        <item name="android:textColor">@drawable/bottom_textcolor_drawable_selector</item>
        <item name="android:textSize">10sp</item>
    </style>
</resources>

bottom_textcolor_drawable_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false" android:color="#363636"/>
    <item android:state_checked="true" android:color="#3097FD"/>
</selector>

activity_main.xml
主页面的布局,采用的是线性布局,头部是标题栏,中间是FrameLayout并且设置权重1,用来显示内容,底部是RadioGroup

<?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=
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值