效果图如下:

项目结构图如下:

ContanctFragment:

package com.demo.moniwexin;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; public class ContanctFragment extends Fragment { @Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_contact, null);
//测试按钮如何点击
Button wxBtn = view.findViewById(R.id.btn_test);
wxBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("点击了通讯录模块");
}
}); return view; }
}

DiscoverFragment:

package com.demo.moniwexin;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; public class DiscoverFragment extends Fragment { @Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_discover, null);
//测试按钮如何点击
Button wxBtn = view.findViewById(R.id.btn_test);
wxBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("点击了发现模块");
}
}); return view;
}
}

MainActivity:

package com.demo.moniwexin;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View; public class MainActivity extends AppCompatActivity implements View.OnClickListener { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); findViewById(R.id.btn_wx).setOnClickListener(this);
findViewById(R.id.btn_contact).setOnClickListener(this);
findViewById(R.id.btn_discover).setOnClickListener(this);
findViewById(R.id.btn_me).setOnClickListener(this);
} @Override
public void onClick(View v) { //获取管理者
FragmentManager fragmentManager =getFragmentManager(); FragmentTransaction beginTransaction = fragmentManager.beginTransaction(); switch (v.getId()){
case R.id.btn_wx :
beginTransaction.replace(R.id.ll_l,new WxFragment());
break;
case R.id.btn_contact:
beginTransaction.replace(R.id.ll_l,new ContanctFragment());
break;
case R.id.btn_discover:
beginTransaction.replace(R.id.ll_l,new DiscoverFragment());
break;
case R.id.btn_me:
beginTransaction.replace(R.id.ll_l,new MeFragment());
break; default: break; } beginTransaction.commit();
}
}

MeFragment:

package com.demo.moniwexin;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; public class MeFragment extends Fragment { @Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_me, null);
//测试按钮如何点击
Button wxBtn = view.findViewById(R.id.btn_test);
wxBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("点击了我模块");
}
}); return view;
}
}

WxFragment:

package com.demo.moniwexin;

import android.app.Fragment;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; public class WxFragment extends Fragment { @Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_wx, null);
//测试按钮如何点击
Button wxBtn = view.findViewById(R.id.btn_test);
wxBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { System.out.println("点击了微信模块"); }
}); return view; }
}

activity_main.xml:

<?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_l"
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:layout_alignParentBottom="true"
android:orientation="horizontal"> <Button
android:id="@+id/btn_wx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="微信" /> <Button
android:id="@+id/btn_contact" android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="通讯录" /> <Button
android:id="@+id/btn_discover" android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="发现" /> <Button
android:id="@+id/btn_me" android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="我" /> </LinearLayout> </RelativeLayout>

fragment_contact.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"> <TextView
android:text="我是通讯录模块的内容"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <Button
android:id="@+id/btn_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试"
/> </LinearLayout>

fragment_discover.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"> <TextView
android:text="我是发现模块的内容"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <Button
android:id="@+id/btn_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试"
/> </LinearLayout>

fragment_me.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"> <TextView
android:text="我是我的模块内容"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <Button
android:id="@+id/btn_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试"
/> </LinearLayout>

fragment_wx.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"> <TextView
android:text="我是微信模块的内容"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <Button
android:id="@+id/btn_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试"
/> </LinearLayout>

Android模拟微信主页面的Demo的更多相关文章

  1. android 模拟微信消息框 BaseAdapter()方法 [2]

    在昨天的微信布局的基础上加内容 http://www.cnblogs.com/Seven-cjy/p/6098024.html 项目下/res/layout下创建一个 listview_layout. ...

  2. android 模拟微信消息 OnItemClickListener()方法 [3]

    在 http://www.cnblogs.com/Seven-cjy/p/6101555.html 是基础上修改 MainActivity.java /winxinmff/src/com/exampl ...

  3. 解决Android微信支付官方demo运行失败

    Android微信支付官方demo运行失败,在此简单记录一下解决步骤 1.httpclient错误 官方给的demo是eclipse的,打开之后提示httpclient的错误,我知道在as下解决htt ...

  4. 记写 android 微信登录的demo历程

    前言 首先看一条链接: https://github.com/Tencent/WeDemo 腾讯给了一个wedemo,微信第三方登录的例子.里面是php和ios,ios是object写的,php还是原 ...

  5. Android仿微信QQ等实现锁屏消息提醒

    demo代码如下: import android.content.Intent; import android.os.Bundle; import android.support.v7.app.App ...

  6. Android模拟位置信息

    Android模拟位置程序,俗称GPS欺骗,只能修改采用GPS定位的软件. 手机定位方式目前有4种:基站定位,WIFI定位,GPS定位,AGPS定位 常见的修改手法: 1. 抓包欺骗法,抓包改包欺骗服 ...

  7. chorme模拟微信浏览器

    chorme模拟微信浏览器 1.代码填入到图中2出 Mozilla/5.0 (Linux; Android 4.4.4; HM NOTE 1LTEW Build/KTU84P) AppleWebKit ...

  8. Android开发 --微信支付开发(转载!)(开发工具:Eclipse)

    Android_APP 微信支付接口开发 日期:2015-10-06 12:47:33 作者: 来源: 人气:3549 1.首先说一下我们在开发微信支付接口的时候遇到最多和最疑惑的问题,那就是明明 a ...

  9. Android 模仿微信启动动画(转)

    本文内容 环境 项目结构 演示微信启动动画 本文演示微信启动动画.请点击此处下载,自行调试. 顺便抱怨一下,实践性(与研究性质的相对)技术博的“七宗罪”: 第一宗罪,错字连篇,逻辑不清: 第二宗罪,文 ...

随机推荐

  1. groupby一个as_index参数解释

  2. 深拷贝 浅拷贝 python

    1. copy.copy 浅拷贝 只拷贝父对象,不会拷贝对象的内部的子对象. 2. copy.deepcopy 深拷贝 拷贝对象及其子对象 一个很好的例子: # -*-coding:utf-8 -*- ...

  3. TZOJ 3820 Revenge of Fibonacci(大数+trie)

    描述 The well-known Fibonacci sequence is defined as following: Here we regard n as the index of the F ...

  4. Mysql 提升大数据表的拷贝效率

    工作上会经常遇到量级比较大的数据表  :场景: 该数据表需要进行alter操作 比如增加一个字段,减少一个字段. 这个在一个几万级别数据量的数据表可以直接进行alter表操作,但是要在一个接近1000 ...

  5. [原]CentOS 7.2 1511部署L2TP/IPsec服务器及客户端

    快过年了,感觉从去年开始,我们公司就变成了“别人的公司”,基本上提前一星期就放假了,好开心.正好可以利用这一段时间,把前段时间一些疑惑的问题解决下:) 然而挡在面前的一个拦路虎是:很多时候不能愉快的G ...

  6. CSS3美化网页!!

    一.span标签:能让某几个文字或者某个词语凸显出来        <p>           今天是11月份的<span>第一天</span>,地铁卡不打折了  ...

  7. Effective C++ 笔记:条款 31 将编译关系降至最低

    31 : Minimize compilation dependencies between files 1 这关乎C++的类(或说都是类惹的祸) 1.1 C++类定义式的问题 C++类定义式不只叙述 ...

  8. ios Block详解

    一. iOS代码块Block 1.1 概述 代码块Block是苹果在iOS4开始引入的对C语言的扩展,用来实现匿名函数的特性,Block是一种特殊的数据类型,其可以正常定义变量.作为参数.作为返回值, ...

  9. 简单易用的图像库stb_image

    最近又回到了选择图像库的老问题上,之前用过FreeImage,DevIL,libpng. FreeImage的问题是他的Licence有点迷,双证书,除了GPL还有个自己的没读懂,不商用的话随便折腾, ...

  10. latex表格代码

     基本代码 \begin{table}[!h] \caption{Notations Used in Real-time Analysis.} \label{table:notation} \cent ...