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 {@Overridepublic 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 {@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_call, null); } }

转载于:https://www.cnblogs.com/wbp0818/p/5453020.html

Android 仿QQ消息界面相关推荐

  1. Android仿QQ主界面-------完善篇

    在我前面的博文中,做出了仿QQ主界面的主要工作,博文地址:Android仿QQ主界面. 但是在那一篇中还有一个不起眼的地方没做,今天就完善它. 今天要实现在文字下面来个ImageView,实现动画.先 ...

  2. Android仿QQ消息拖拽效果(二)

    前言 本文参考辉哥贝塞尔曲线 - QQ消息汽包拖拽,前面我们使用二阶贝塞尔曲线绘制了拖拽圆点效果Android仿QQ消息拖拽效果(一)(二阶贝塞尔曲线使用),这里我们在此基础之上实现仿QQ消息拖拽爆炸 ...

  3. Android 仿qq聊天界面之一

    一.登录界面 本来是只想仿一个qq的聊天界面的,顺便做了一个登录界面,熟悉下SharedPreferences(解释一下:SharedPreferences由于非常适合记录一些零散的简单的数据,因此登 ...

  4. Android仿QQ登录界面示例,实现登录、注册功能。

    首语 欢迎大家关注我的公众号:八归少年 微信公众号优先更新文章.扫描上面二维码即可关注!一起进步,一同成长. Android开发经常用到注册.登录功能,于是便整理出一般通用的登录界面,并实现其相应功能 ...

  5. Android仿QQ主界面

    Android版的QQ使用的是ViewPager实现的,主要是可以实现TabHost的界面,但功能比Tabhost更好,因为可以实现用手滑动实现界面的切换.QQ的截图如下 : 下面我来实现这个效果 工 ...

  6. Android仿QQ消息拖拽黏连消失效果,气泡爆炸效果

    公司需要这个效果,看了很多博客,根据自己项目的需要写出来的一个完整的过程. 拖拽控件代码 根据手势拖动的位置利用贝塞尔曲线算法画出控件 package cn.stike.bubble.stickbub ...

  7. android 仿QQ登陆界面实现

    android 现在越来越火,之前大量的桌面软件,现在都开发出android版了.最近也在学习android,顺便做了几个demo.不说废话了,上图. 接下来是布局: <RelativeLayo ...

  8. android 仿qq修改头像,Qt:小项目仿QQ修改头像界面,技术点记录

    最近写了一个修改头像功能的UI,布局参考了QQ目前的修改头像界面.如下图 这里主要说明一下两个地方的技术:1.头像图片上层的遮罩层,圆形外部为灰色,内部为全透明:2.上传图片宽高比例可以通过鼠标拖拽移 ...

  9. Android开发之高仿QQ消息侧拉删除

    Android开发之高仿QQ消息侧拉删除 QQ消息的侧滑删除效果之炫酷,想必大家都见过吧,本人作为一名安卓开发人员,遇到如此炫酷的效果,怎能不研究一番呢,现本人已实现其基本功能,现将代码贴出,望各位大 ...

最新文章

  1. python基础代码库-python3.4第三方库的安装?python基础代码库
  2. 借助混沌工程工具 ChaosBlade 构建高可用的分布式系统
  3. Java面试宝典系列之基础面试题String、变量、类与对象、集合类、SSH(一)
  4. 关于如何存储便于网上浏览的电子书籍
  5. C++派生类的构造函数和析构函数
  6. java统计文件字符数量_Java统计文件注释个数和注释字符数
  7. java给按钮加声音_怎么在java中给按钮添加声音?
  8. “不做信奥比赛,不做等级考试”的童心制物,是如何在 STEAM 教育突出重围?
  9. Hyperledger Fabric教程(14)--byfn.sh所有命令
  10. 10款开源网上教学课程管理系统
  11. mysql设置report_host语法_MySQL_mysqlreport 中文文档,mysqlreport 以很友好的方式显示 - phpStudy...
  12. 分层图解决的一些最短路问题
  13. 我不是蓝牙大神,但还是斗胆对蓝牙学习路线给点建议!
  14. Unity学习-RTTM总结(1)
  15. 工控随笔_05_西门子_Step7软件仿真方法
  16. java实现简单的电竞房间预定
  17. 人工智能 一种现代方法 第10章 经典的规划问题(classical planning)
  18. 如何在editplus中配置ctags?
  19. 在400亿防脱发蓝海里,霸王要“躺平”了?
  20. 【灵动MM32-DMA传输-GPS解算】 移植NMEA协议库解析GGA数据格式

热门文章

  1. Let’ s Encrypt 现支持通配符的 HTTPS 认证
  2. maven入门(7)maven项目(组件)的坐标
  3. 特别推荐:开发者的10个最佳代码游乐场
  4. 带“公交一卡通功能”的智能手环会是用户最爱?
  5. 香蕉派开源硬件 Banana PI
  6. 技术公开课:SQL Server 高可用性解决方案概述(下)
  7. CentOS 6.3下Apache+SVN部署Web版本同步
  8. boost库的lock_ops类的变化
  9. jQueryPager(JQuery分页插件pagination实现Ajax分页)
  10. 如何修改Windows 7登录界面默认输入法?