Android Fragment实现微信底部导航
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实现微信底部导航的更多相关文章
- [Android] Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单
Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单 利用FragmentTabHost实现底部菜单,在该底部菜单中,包括了4个TabSpec,每个TabS ...
- 二、Fragment+RadioButton实现底部导航栏
在App中经常看到这样的tab底部导航栏 那么这种效果是如何实现,实现的方式有很多种,最常见的就是使用Fragment+RadioButton去实现.下面我们来写一个例子 首先我们先在activi ...
- Android UI-仿微信底部导航栏布局
现在App基本的标配除了侧滑菜单,还有一个就是底部导航栏,常见的聊天工具QQ,微信,购物App都有底部导航栏,用户可以随便切换看不同的内容,说是情怀也好,用户体验也罢.我们开发的主要的还是讲的是如何如 ...
- 【简单项目框架一】Fragment实现的底部导航
流行的应用的导航一般分为两种,一种是底部导航,一种是侧边栏. 我所做的项目涉及到比较多的是底部导航,今天我就把项目中使用的一种实现方式分享一下. 主要实现思路是:在一个Activity里面底部添加四个 ...
- [Android]--RadioGroup+RadioButton实现底部导航栏
RadioGroup+RadioButton组合方式打造简单实用的底部导航栏 代码块: <?xml version="1.0" encoding="utf-8&qu ...
- Android 高仿新浪微博底部导航栏,实现双击首页Tab,页面的ListView滚动、刷新
现在很多APP,如微信.QQ.微博等等,它们的主页面都无一例外的选择使用底部Tab导航, 通过这种方式,可以很好的把页面层级分化,很好的提高用户体验.相信,很多Android开发者,都使用到过这种经典 ...
- Android 仿QQ微信开场导航以及登陆界面
相信大家对于微信等社交应用的UI界面已经都很熟悉了,该UI最值得借鉴的莫过于第一次使用的时候一些列产品介绍的图片,可以左右滑动浏览,最后进入应 用,这一效果适用于多种项目中,相信今后开发应用一定会用得 ...
- Android仿QQ微信开场导航以及登陆界面
相信大家对于微信等社交应用的UI界面已经都很熟悉了,该UI最值得借鉴的莫过于第一次使用的时候一些列产品介绍的图片,可以左右滑动浏览,最后 进入应用,这一效果适用于多种项目中,相信今后开发应用一定会用得 ...
- Android -- FragmentTabHost实现微信底部切换
1,在商城类的项目中我们开始一个项目的时候经常出现这样的需求,如下图所示: 下面使用户可以切换的模块,上面是对应的模块的详细内容,实现这个效果有很多方式,可以使用radiobutton+fragmen ...
随机推荐
- WIFI配置专项测试
1. 测试项目 A. 路由器加密方式测试: B. 路由器信道选择测试: C. DHCP过期时间测试 D. 路由器WIFI密码复杂度测试: 2. 测试结果 2.1. 加密方式测试 路由器密码为简单,其他 ...
- PythonQt第一例
pythonQt第一例源码如下,主要介绍了简单的使用方式,需要注意的是应用程序的debug版本和release版本必须使用同类型的PythonQt库不可交叉使用. 源码地址:http://files. ...
- ECC 算法
一.简介 1)椭圆曲线密码学的初级读本 http://8btc.com/thread-1240-1-1.html 2)ECC加密算法入门介绍 http://www.pediy.com/kssd/ped ...
- Jedis连接Redis三种模式
这里说的三种工作模式是指: 1.单机模式 2.分片模式 3.集群模式(since 3.0) 说明图详见以下: 使用单机模式连接: private String addr="192.168.1 ...
- 一些命令可以帮您了解Linux 操作系统用户信息
1 显示上次登录的用户信息列表,包括(登录时间.退出时间.登录IP): [sywu@wusuyuan ~]$ last root pts/1 192.168.1.3 Wed Aug 27 22:08 ...
- Discuz核心函数的解析
dz采用的是多入口的方式,在每个入口函数你能看到引用,启动核心类的语句(其余省略),如下: require './source/class/class_core.php'; C::app()-> ...
- Logback configuration
官方指导 http://logback.qos.ch/manual/configuration.html 规则 ch.qos.logback.core.joran.JoranConfiguratorB ...
- ORB_SLAM2应用实践_ROS小强机器人
http://www.cnblogs.com/2008nmj/p/6166282.html
- linux 学习管道 和重定向
开源文化的理念之一 就是不要重新发明轮子 在linux 系统中大多是都是非常简单的命令,每个命令都是实现一个或者几个简单的功能,我们可以将不同的命令组合在一起 来达到复杂的功能的目的,在linux中因 ...
- 关于Markdown格式转PDF格式
Markdown转PDF格式 个人使用的Markdown编辑平台:有道云笔记网页版 当我们编辑好自己的随笔以后,在网页的[客户端下载]下面有一个[更多]的圆形图标选项,点击后在菜单中有一处[打印]选项 ...