1.XML布局

(1)主界面

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"> <LinearLayout
android:id="@+id/ll_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> </LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"> <Button
android:id="@+id/btmain_weixin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="微信" /> <Button
android:id="@+id/btmain_tongxunlu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="通讯录" /> <Button
android:id="@+id/btmain_discover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="发现" /> <Button
android:id="@+id/btmain_wo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="我" />
</LinearLayout> </RelativeLayout>

(2)Fragment对应的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:orientation="vertical"> <TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是weixin模块" /> <Button
android:id="@+id/bt_weixin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试weixin" /> </LinearLayout>

2.java后台代码

(1)MainActivity.java

package com.example.administrator.test57wechat;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btmain_weixin=findViewById(R.id.btmain_weixin);
Button btmain_tongxunlu=findViewById(R.id.btmain_tongxunlu);
Button btmain_wo=findViewById(R.id.btmain_wo);
Button btmain_discover=findViewById(R.id.btmain_discover);
btmain_weixin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//1.获取Fragment的管理者
FragmentManager fragmentManager=getSupportFragmentManager();
//2.开启事务
FragmentTransaction beginTransaction=fragmentManager.beginTransaction();
//3.替换Fragment
beginTransaction.replace(R.id.ll_layout,new WeixinFragment());
beginTransaction.commit();
}
}); btmain_tongxunlu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//1.获取Fragment的管理者
FragmentManager fragmentManager=getSupportFragmentManager();
//2.开启事务
FragmentTransaction beginTransaction=fragmentManager.beginTransaction();
//3.替换Fragment
beginTransaction.replace(R.id.ll_layout,new TongxunluFragment());
beginTransaction.commit();
}
}); btmain_wo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//1.获取Fragment的管理者
FragmentManager fragmentManager=getSupportFragmentManager();
//2.开启事务
FragmentTransaction beginTransaction=fragmentManager.beginTransaction();
//3.替换Fragment
beginTransaction.replace(R.id.ll_layout,new WoFragment());
beginTransaction.commit();
}
}); btmain_discover.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//1.获取Fragment的管理者
FragmentManager fragmentManager=getSupportFragmentManager();
//2.开启事务
FragmentTransaction beginTransaction=fragmentManager.beginTransaction();
//3.替换Fragment
beginTransaction.replace(R.id.ll_layout,new DiscoverFragment());
beginTransaction.commit();
}
});
}
}

(2)Fragment

package com.example.administrator.test57wechat;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; public class WeixinFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_weixin,null); //测试fragment中的组件是否可以被点击
Button bt_weixin=view.findViewById(R.id.bt_weixin);
bt_weixin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("hello weixin");
}
});
return view;
}
}

3.效果图

对应的工程名:test57

Android Fragment实现微信底部导航的更多相关文章

  1. [Android] Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单

    Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单 利用FragmentTabHost实现底部菜单,在该底部菜单中,包括了4个TabSpec,每个TabS ...

  2. 二、Fragment+RadioButton实现底部导航栏

    在App中经常看到这样的tab底部导航栏   那么这种效果是如何实现,实现的方式有很多种,最常见的就是使用Fragment+RadioButton去实现.下面我们来写一个例子 首先我们先在activi ...

  3. Android UI-仿微信底部导航栏布局

    现在App基本的标配除了侧滑菜单,还有一个就是底部导航栏,常见的聊天工具QQ,微信,购物App都有底部导航栏,用户可以随便切换看不同的内容,说是情怀也好,用户体验也罢.我们开发的主要的还是讲的是如何如 ...

  4. 【简单项目框架一】Fragment实现的底部导航

    流行的应用的导航一般分为两种,一种是底部导航,一种是侧边栏. 我所做的项目涉及到比较多的是底部导航,今天我就把项目中使用的一种实现方式分享一下. 主要实现思路是:在一个Activity里面底部添加四个 ...

  5. [Android]--RadioGroup+RadioButton实现底部导航栏

    RadioGroup+RadioButton组合方式打造简单实用的底部导航栏 代码块: <?xml version="1.0" encoding="utf-8&qu ...

  6. Android 高仿新浪微博底部导航栏,实现双击首页Tab,页面的ListView滚动、刷新

    现在很多APP,如微信.QQ.微博等等,它们的主页面都无一例外的选择使用底部Tab导航, 通过这种方式,可以很好的把页面层级分化,很好的提高用户体验.相信,很多Android开发者,都使用到过这种经典 ...

  7. Android 仿QQ微信开场导航以及登陆界面

    相信大家对于微信等社交应用的UI界面已经都很熟悉了,该UI最值得借鉴的莫过于第一次使用的时候一些列产品介绍的图片,可以左右滑动浏览,最后进入应 用,这一效果适用于多种项目中,相信今后开发应用一定会用得 ...

  8. Android仿QQ微信开场导航以及登陆界面

    相信大家对于微信等社交应用的UI界面已经都很熟悉了,该UI最值得借鉴的莫过于第一次使用的时候一些列产品介绍的图片,可以左右滑动浏览,最后 进入应用,这一效果适用于多种项目中,相信今后开发应用一定会用得 ...

  9. Android -- FragmentTabHost实现微信底部切换

    1,在商城类的项目中我们开始一个项目的时候经常出现这样的需求,如下图所示: 下面使用户可以切换的模块,上面是对应的模块的详细内容,实现这个效果有很多方式,可以使用radiobutton+fragmen ...

随机推荐

  1. sqlserver服务器硬件性能瓶颈分析

    硬件性能瓶颈 内存 内存对SQL Server性能的影响胜过任何其他硬件.因此,对SQL Server系统的内存使用情况进行定期监视以确保内存的可用百分比高于20%是很有必要的.如果用户遭遇性能问题, ...

  2. 面向对象的JavaScript-001

    一. Question是父类,MultipleChoiceQuestion和DragDropQuestion是子类 二. 1. <script> // 面向对象 function Ques ...

  3. Video组件:控制视频的播放与暂停

    来自<sencha touch权威指南>第10章,315页开始 app.js代码如下: Ext.require(['Ext.Video','Ext.MessageBox','Ext.Too ...

  4. code2102 石子归并2

    划分dp 注意环形,需要把原数复制成两份再进行,详见: http://www.cnblogs.com/FuTaimeng/p/5427426.html 初始条件:dp[i][i]=0 转移方程:dp[ ...

  5. 最近公共祖先 LCA Tarjan算法

    来自:http://www.cnblogs.com/ylfdrib/archive/2010/11/03/1867901.html 对于一棵有根树,就会有父亲结点,祖先结点,当然最近公共祖先就是这两个 ...

  6. linux环境下搭建osm_web服务器四(对万国语的地名进行翻译和检索):

    对万国语的地名进行翻译和检索 经过 前三篇的调试,已经有了一个完整的Map可以浏览,我们痛苦的世界范围数据下载.导入过程也结束了.要提醒一下的是,鉴于网速,不要下载 planetosm.lastest ...

  7. PHP中PSR

    PSR 是 PHP Standard Recommendations 的简写,由 PHP FIG 组织制定的 PHP 规范,是 PHP 开发的实践标准. 文档整理 PSR-0: Autoloading ...

  8. Word文档如何发CSDN博客

    目前大部分的博客作者在写博客这件事情上都会遇到以下3个痛点:1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.2.发布到博客或公众号平台 ...

  9. 使用ffmpeg+crtmpserver搭建文件的伪直播

    Tutorial: How to "live stream" a media file 如何"直播"一个媒体文件 I have tried a while to ...

  10. opencv——通过面积筛选最大轮廓,并求凸包矩形的长和宽

    #include "stdafx.h" #include <iostream> #include<string> #include <stdio.h& ...