首页 > 其他 > 详细

使用fragment添加底部导航栏

时间:2016-08-09 14:50:21      阅读:256      评论:0      收藏:0      [点我收藏+]

切记: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添加底部导航栏

原文:http://www.cnblogs.com/judes/p/5753171.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!