activity_main.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" > <FrameLayout
android:id="@+id/mHomeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/mRadioGroup" >
</FrameLayout> <RadioGroup
android:id="@+id/mRadioGroup"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:background="@drawable/main_bottom_bg"
android:orientation="horizontal" > <ImageView
android:id="@+id/Tab_Conversation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@null"
android:src="@drawable/skin_tab_icon_conversation_selected" /> <ImageView
android:id="@+id/Tab_Contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@null"
android:src="@drawable/skin_tab_icon_contact_normal" /> <ImageView
android:id="@+id/Tab_Plugin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@null"
android:src="@drawable/skin_tab_icon_plugin_normal" />
</RadioGroup> </RelativeLayout>

关键代码:

 import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.content.Context;
import android.os.Bundle; @ContentView(R.layout.activity_main)
public class MainActivity extends ActionBarActivity { @ViewInject(R.id.Tab_Conversation)
private ImageView Tab_Conversation;
@ViewInject(R.id.Tab_Contact)
private ImageView Tab_Contact;
@ViewInject(R.id.Tab_Plugin)
private ImageView Tab_Plugin; private FragmentConversation mFragmentConversation;
private FragmentContact mFragmentContact;
private FragmentPlugin mFragmentPlugin;
private Context mContext; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
ViewUtils.inject(this);
mContext = this;
InitFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.mHomeContainer, mFragmentConversation).commit();
} private void InitFragment() {
mFragmentConversation = new FragmentConversation();
mFragmentContact = new FragmentContact();
mFragmentPlugin = new FragmentPlugin();
} /**
* 隐藏其他所有Fragment
*/
private void HideOtherFragments(Fragment fragment) {
if (getSupportFragmentManager().getFragments() == null) {
return;
}
for (Fragment fm : getSupportFragmentManager().getFragments()) {
if (fm != fragment) {
getSupportFragmentManager().beginTransaction().hide(fm)
.commit();
}
}
} /**
* Tab切换
*
* @param view
*/
@OnClick({ R.id.Tab_Conversation, R.id.Tab_Contact, R.id.Tab_Plugin })
private void OnTabSelected(View view) {
ClearSelection();
FragmentTransaction mTransaction = getSupportFragmentManager()
.beginTransaction();
switch (view.getId()) {
case R.id.Tab_Conversation:
Tab_Conversation.setImageDrawable(getResources().getDrawable(
R.drawable.skin_tab_icon_conversation_selected));
if (!getSupportFragmentManager().getFragments().contains(
mFragmentConversation)) {
mTransaction.add(R.id.mHomeContainer, mFragmentConversation);
}
mTransaction.show(mFragmentConversation);
HideOtherFragments(mFragmentConversation);
break;
case R.id.Tab_Contact:
Tab_Contact.setImageDrawable(getResources().getDrawable(
R.drawable.skin_tab_icon_contact_selected));
if (!getSupportFragmentManager().getFragments().contains(
mFragmentContact)) {
mTransaction.add(R.id.mHomeContainer, mFragmentContact);
}
mTransaction.show(mFragmentContact);
HideOtherFragments(mFragmentContact);
break;
case R.id.Tab_Plugin:
Tab_Plugin.setImageDrawable(getResources().getDrawable(
R.drawable.skin_tab_icon_plugin_selected));
if (!getSupportFragmentManager().getFragments().contains(
mFragmentPlugin)) {
mTransaction.add(R.id.mHomeContainer, mFragmentPlugin);
}
mTransaction.show(mFragmentPlugin);
HideOtherFragments(mFragmentPlugin);
break;
default:
break;
}
mTransaction.commit();
} /**
* 清除所有选中状态
*/
private void ClearSelection() {
Tab_Conversation.setImageDrawable(getResources().getDrawable(
R.drawable.skin_tab_icon_conversation_normal));
Tab_Contact.setImageDrawable(getResources().getDrawable(
R.drawable.skin_tab_icon_contact_normal));
Tab_Plugin.setImageDrawable(getResources().getDrawable(
R.drawable.skin_tab_icon_plugin_normal));
} }

最新文章

  1. ASP.NET Core 中文文档 第四章 MVC(2.1)模型绑定
  2. Atitit 热更新资源管理器&#160;自动更新管理器&#160;功能设计
  3. java rest接口返回不完整的json数据
  4. PHP 如何安全的使用 MySQL ?
  5. 【转】24. android dialog ——ProgressDialog 进度条对话框详解
  6. xml在此生活
  7. 【踩坑速记】MIUI系统BUG,调用系统相机拍照可能会带给你的一系列坑,将拍照适配方案进行到底!
  8. spring从服务器磁盘读取图片,然后显示于前端页面上
  9. linux常用命令说明
  10. html5-新元素新布局模板-完善中
  11. 201621123001 《java程序设计》第2周学习总结
  12. 移动端font-size适配方案
  13. assign()函数
  14. EntityFramework 5.0 CodeFirst 教程02-删除和修改/架构改变异常的处理
  15. windows7 安装IIS没有default web site 解决方法
  16. Win10巧用自带输入法轻松打出特殊字符
  17. linux 下配置vncserver
  18. python 面向对象&#183; self 讲解
  19. Qt多线程-QtConcurrent并行运算高级API
  20. Bugfree安装与使用

热门文章

  1. JSTL与EL之间的千丝万缕
  2. 10.使用final关键字修饰一个变量时...
  3. 多线程12-CyclicBarrier、CountDownLatch、Exchanger
  4. 趣味PAT--循环-19. 币值转换(20)
  5. php判断是移动端还是pc
  6. 转:Twitter.com在用哪些Javascript框架?
  7. Laravel 依赖注入原理
  8. yiic模块module使用
  9. HASH JOIN算法
  10. guestfish 修改 image file