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. Git fetch和git pull的区别

    Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge git fetch origin mastergit log - ...

  2. 获取文件hash值

    public string getFilesMD5Hash(string file)        {            //MD5 hash provider for computing the ...

  3. 解决Android Studio Gradle Build Running慢的问题

    Android Studio方便好用,但是Android Studio Gradle Build Running很慢 解决方法: C:\Users\你的用户名\.gradle 目录下新建一个文件名为 ...

  4. shujuk

    数据库管理的目标:在适当的时候以适当的形式向适当的人提供适当的数据. 2. 数据管理的内容:组织业务的管理(学生的信息) :技术的管理(数据库的建立等) 3. 数据库管理的发展阶段:人工,文件,数据库 ...

  5. MyBatis学习总结(六)——调用存储过程(转载)

    本文转载自:http://www.cnblogs.com/jpf-java/p/6013518.html 一.提出需求 查询得到男性或女性的数量, 如果传入的是0就女性否则是男性 二.准备数据库表和存 ...

  6. log4j使用快速入门【转】

    1.引言 在应用程序中添加日志记录总的来说基于三个目的: .监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作 .跟踪代码运行时轨迹,作为日后审计的依据 .担当集成开发环境中的调 ...

  7. Glide请求图片能携带Cookie的哟!

    在Web编程中我们都很熟知一个概念,当有了seesion登录状态时,你可以访问一些资源但如果你没有登录的话很多资源是无法访问的. 在android的WebApi中当然一样拥有这个概念.比如,用户的头像 ...

  8. 启动eclipse时:java is started but returned code 13

    此问题是eclipse位数和java位数不匹配造成的 我的是win10 64位的eclipse + 32位的java造成的问题 查看eclipse位数:用记事本打开eclipse根目录下的eclips ...

  9. 使用clearInterval清除计时循环时,最后一次循环还是会执行解决办法

    原代码: var interv=setInterval(function(){ alert("setInterval执行"); },2000) clearInterval(inte ...

  10. linear-gradient----渐变

    CSS3 渐变(gradient)可以让你在两个或多个指定的颜色之间显示平稳的过渡. 以前,你必须使用图像来实现这些效果,现在通过使用 CSS3 的渐变(gradients)即可实现.此外,渐变效果的 ...