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 ...
随机推荐
- Linux系统巡检常用命令-乾颐堂
Linux系统需要定期巡检,以检查服务器软硬件使用情况,相当于对人的体检,确保可以及时发现问题.解决问题,降低损失,常用的巡检命令如下: # uname -a # 查看内核/操作系统/CPU信息 # ...
- C#调用COM组件遇到的问题及解决办法
1.无法嵌入互操作类型"xxx",请改用适用的接口. 解决办法: - 将所引用的程序集的[嵌入互操作类型]属性设置为[False]. 2.System.Runtime.Intero ...
- SpringMVC错误集中营
1.eclipse里的错误提示为The import javax.servlet.http.HttpServletRequest cannot be resolved 1.这是因为工程里面web-in ...
- 编写高质量代码改善C#程序的157个建议——建议75:警惕线程不会立即启动
建议75:警惕线程不会立即启动 现代的大多数操作系统都不是一个实时的操作系统,Windows系统也是如此.所以,不能奢望我们的线程能够立即启动.Windows内部会实现特殊的算法以进行线程之间的调度, ...
- mybatis Mapper.xml和Mapper.java
mybatis Mapper.xml和Mapper.java 通过Mapper.xml和Mapper.java来实现mybatis.环境和入门的一样的.关键:Mapper.xml + Mapper.j ...
- 深入理解java虚拟机(五)垃圾收集器
垃圾收集器 垃圾收集器是垃圾收集算法的具体实现.Java规范对垃圾收集器的实现没有做任何规定,因此不同的虚拟机提供的垃圾收集器可能有很大差异.HotSpot虚拟机1.7版本使用了多种收集器.如下图. ...
- 【小梅哥SOPC学习笔记】Altera SOPC嵌入式系统设计教程
Altera SOPC嵌入式系统设计教程 第1章 概述 SOPC(System On Programmable Chip,可编程的片上系统)是Altera公司提出来的一种灵活.高效的SOC解决方案.它 ...
- Acrobat_8_Pro_SC 激活老是提示你输入的授权码无效
假如安装了Adobe Acrobat Professional 8 的时候无法激活, 或在恢复安装时 Adobe Acrobat Professional 8 需要重新激活, 激活的时候,总是提示你输 ...
- CSS中的一些内容总结
一.选择器 1.选择器的分组:一个Style可以对多个选择器生效,只用在不同的选择器中间加入逗号即可.如: h1,h2,h3,h4,h5,h6 { color: green; } PS:CSS规定,所 ...
- sonar安装问题记录
1.启动时日志中提示 Caused by: java.lang.RuntimeException: can not run elasticsearch as root 错误原因:因为安全问题elast ...