values 下面

dimens.xml

<resources>

    <!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen> </resources>

主布局

activity_switch.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <RelativeLayout
android:id="@+id/rl_header"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:background="#df3031" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:paddingLeft="8.0dp" > <Button
android:id="@+id/btn_message"
android:layout_width="70dip"
android:layout_height="30dip"
android:background="@drawable/baike_btn_pink_left_f_96"
android:gravity="center"
android:text="消息"
android:textColor="#df3031"
android:textSize="14sp" /> <Button
android:id="@+id/btn_call"
android:layout_width="70dip"
android:layout_height="30dip"
android:background="@drawable/baike_btn_trans_right_f_96"
android:gravity="center"
android:text="电话"
android:textColor="#ffffff"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout> <FrameLayout
android:id="@+id/fl_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /> </LinearLayout>

两个fragment

fragment_message.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"
android:gravity="center"
android:background="#BED0E2"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="消息界面"
android:textColor="#000000"/> </LinearLayout>

fragment_call.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"
android:gravity="center"
android:background="#BED0E2"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="电话界面"
android:textColor="#000000"/> </LinearLayout>

主页面

SwitchActivity.java

package com.example.switchutils;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button; public class SwitchActivity extends FragmentActivity { private Button btn_message,btn_call; private CallFragment callFragment;
private MessageFragment messageFragment; public static final int MESSAGE_FRAGMENT_TYPE = 1;
public static final int CALL_FRAGMENT_TYPE = 2;
public int currentFragmentType = -1; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_switch); btn_message = (Button)findViewById(R.id.btn_message);
btn_call = (Button)findViewById(R.id.btn_call);
btn_message.setOnClickListener(onClicker);
btn_call.setOnClickListener(onClicker); FragmentManager fragmentManager = getSupportFragmentManager();
if (savedInstanceState != null) {
int type = savedInstanceState.getInt("currentFragmentType");
messageFragment = (MessageFragment)fragmentManager.findFragmentByTag("message");
callFragment = (CallFragment)fragmentManager.findFragmentByTag("call");
if(type > 0)
loadFragment(type);
} else {
FragmentTransaction transaction = fragmentManager
.beginTransaction();
Fragment mainFragment = fragmentManager.findFragmentByTag("message");
if (mainFragment != null) {
transaction.replace(R.id.fl_content, mainFragment);
transaction.commit();
} else {
loadFragment(MESSAGE_FRAGMENT_TYPE);
}
} } @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("lastFragmentTag", currentFragmentType);
} private void switchFragment(int type) {
switch (type) {
case MESSAGE_FRAGMENT_TYPE:
loadFragment(MESSAGE_FRAGMENT_TYPE);
break;
case CALL_FRAGMENT_TYPE:
loadFragment(CALL_FRAGMENT_TYPE);
break;
} } private void loadFragment(int type) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
if (type == CALL_FRAGMENT_TYPE) {
if (callFragment == null) {
callFragment = new CallFragment(); transaction.add(R.id.fl_content, callFragment, "zhishi");
} else {
transaction.show(callFragment);
}
if (messageFragment != null) {
transaction.hide(messageFragment);
}
currentFragmentType = MESSAGE_FRAGMENT_TYPE;
} else {
if (messageFragment == null) {
messageFragment = new MessageFragment();
transaction.add(R.id.fl_content, messageFragment, "wenda");
} else {
transaction.show(messageFragment);
}
if (callFragment != null) {
transaction.hide(callFragment);
}
currentFragmentType = CALL_FRAGMENT_TYPE;
}
transaction.commitAllowingStateLoss();
} private OnClickListener onClicker = new OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_message:
btn_message.setTextColor(Color.parseColor("#df3031"));
btn_call.setTextColor(Color.WHITE);
btn_message
.setBackgroundResource(R.drawable.baike_btn_pink_left_f_96);
btn_call
.setBackgroundResource(R.drawable.baike_btn_trans_right_f_96);
switchFragment(MESSAGE_FRAGMENT_TYPE); break;
case R.id.btn_call: btn_message.setTextColor(Color.WHITE);
btn_call.setTextColor(Color.parseColor("#df3031"));
btn_message
.setBackgroundResource(R.drawable.baike_btn_trans_left_f_96);
btn_call
.setBackgroundResource(R.drawable.baike_btn_pink_right_f_96);
switchFragment(CALL_FRAGMENT_TYPE); break; }
}
}; }

两个fragment

MessageFragment.java

package com.example.switchutils;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; public class MessageFragment extends Fragment { @Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_message, null);
} }

CallFragment.java

package com.example.switchutils;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; public class CallFragment extends Fragment { @Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_call, null);
}
}

Android 仿QQ消息界面的更多相关文章

  1. Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制)

    Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制) 首先贴上七个控制布局代码 1.title_text_sel.xml 字体颜色的切换 放到color文件夹下面 <?xm ...

  2. 高仿qq聊天界面

    高仿qq聊天界面,给有需要的人,界面效果如下: 真心觉得做界面非常痛苦,给有需要的朋友. chat.xml <?xml version="1.0" encoding=&quo ...

  3. WPF开发实例——仿QQ登录界面

    原文:WPF开发实例--仿QQ登录界面 版权声明:本文为博主原创文章,如需转载请标明转载地址 http://blog.csdn.net/u013981858 https://blog.csdn.net ...

  4. Android仿QQ ios dialog,仿QQ退出向上菜单

    Android仿QQ ios dialog,仿QQ退出向上菜单 EasyDialog两种模式 仿QQ退出向上菜单,自己定义向上菜单              github地址:https://gith ...

  5. wpf实现仿qq消息提示框

    原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...

  6. 编写Java程序,使用Swing布局管理器和常用控件,实现仿QQ登录界面

    返回本章节 返回作业目录 需求说明: 使用Swing布局管理器和常用控件,实现仿QQ登录界面 实现思路: 创建登录界面的类QQLogin,该类继承父类JFrame,在该类中创建无参数的构造方法,在构造 ...

  7. Android仿QQ界面

    最近这几天,一直跟着朋友们聚会什么的,没怎么做项目,今天总算是有时间开电脑继续做我的项目了.下面我就把我做的效果展示一下. 这是模仿了qq的界面效果.因为代码比较长就不粘贴代码了.需要的小伙伴可以跟我 ...

  8. android 仿QQ手机版

    千人2群开启,欢迎大家围观打酱油,群号145667827     您当前位置 : JavaApk-安卓应用游戏源码服务专家 » QQ » Android项目源码界面超级华丽的仿QQ最新版本 Andro ...

  9. 仿QQ大战—界面篇

    之前在<仿QQ大战-服务器的搭建(ServerSocket)>中实现了服务器的搭建,以及一个简单地传递数据的实现,现在就是来实现类似与QQ聊天通信的功能.首先是界面的实现: 首先:服务器和 ...

随机推荐

  1. stl文件格式

    http://wenku.baidu.com/view/a3ab7a26ee06eff9aef8077b.html [每个三角形面片的定义包括三角形各个定点的三维坐标及三角形面片的法矢量[三角形的法线 ...

  2. C fread

    fread是一个函数.从一个文件流中读数据,最多读取count个元素,每个元素size字节,如果调用成功返回实际读取到的元素个数,如果不成功返回 0. 函数原型 size_t fread ( void ...

  3. 学习使用html与css,并尝试写php

    这两天看了一点php,本想着实践一下,发现自己的服务器还没弄好,php的代码只写了两三行嵌在html中,还运行不了,同时还发现自己这几天学的html和css还不够,总是频频出现问题,学习的样式和布局都 ...

  4. Ubuntu使用阿里云软件源

    如果在安装Ubuntu时,选择的地区为美国,建议更新为阿里云或国内 软件源 sudo sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt ...

  5. The Path Attribute

    https://tools.ietf.org/html/rfc6265#section-5.1.1 4.1.2.4. The Path Attribute The scope of each cook ...

  6. Mybatis与Spring整合,使用了maven管理项目,作为初学者觉得不错,转载下来

    转载自:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn archetype ...

  7. CG_INLINE,inline 内联函数

    内联函数,即在编译的时候将函数体替换函数调用,从而不需要将parameter,return address进行push/pop stack的操作,从而加速app的运行,然而,会增加二进制文件的大小. ...

  8. 视图UIView的大小和位置属性详解

    UIView类中定义了三个属性,分别是frame.bounds与center属性: IKit中的坐标系X轴正方向为水平向右,Y轴正方向为竖直向下. frame属性指的是视图在其父视图坐标系中的位置与尺 ...

  9. ios10 safari 的坑!

    | 导语 ios10 的safari,又给前端开发者挖坑了..测试验证此问题只出现在ios10 safari中.想早点知道结论的,可以直接看最后一个结论~因为,解决过程不重要! 个人原创,未经允许,禁 ...

  10. vim - line

    copy complete current line: yy replace a char (e.g. comma) to new line: %s/,/\r/g