使用fragment添加底部导航栏
切记:fragment一定要放在framlayout中,不然不会被替换完全(就是切换之后原来的fagment可能还会存在)
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<fragment
android:name="com.liu25.asmallpark.Fragment.Fragment_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_1" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--四个Button>
<LinearLayout/>
<LinearLayout/>
fragment_1.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:background="#f3f3f3"
android:orientation="vertical">
</LinearLayout>
fragment_2.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:background="#000000"
android:orientation="vertical">
</LinearLayout>
main.java
在Button点击事件里面:
FragmentManager fragmentManager = getFragmentManager();//
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.content, fragment_1);
transaction.commit();
彩蛋:在fragment中获得Context:view.getContext()
最新文章
- VirtualBox动态添加虚拟硬盘
- JSR 303 - Bean Validation 介绍及最佳实践
- matlab cross 3*1 向量叉乘
- lucas 定理学习
- linux权威指南 简记
- javascript基础学习(四)
- 【移动开发】Android中WIFI开发总结(一)
- OCP-1Z0-051-题目解析-第11题
- Chapter 2 Open Book——20
- 【Python】Non-ASCII character '\xe6' 错误解决方法
- Android破解学习之路(二)——Android游戏 滚动的天空破解
- java程序的加载过程
- C++笔记019:C++中的const修饰的是一个真正的常量
- 使用VC建立网络连接并访问网络资源
- .NET应用程序管理服务AMS设计
- iperf 2.05版本升级到2.0.9
- 一些常用的mysql语句实例-以后照写2
- php根据命令行参数生成配置文件
- Qt编写视频播放器(vlc内核)
- 如果不用jQuery,Ajax你还能写出多少?
热门文章
- tun笔记
- Excel-字符串连接
- kubernetes实战(十六):k8s高可用集群平滑升级 v1.11.x 到v1.12.x
- qt——QObject 与 QWidget 的区别
- 【F12】九个Console命令,让js调试更简单
- SQL Server表分区-水平分区
- vue使用resource传参数
- Bus System(Flody)
- PAT 1032 Sharing[hash][链表][一般上]
- python3中替换python2中cmp函数