<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/LinearLayout1"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.example.frangment.MainActivity" >    <FrameLayout                  android:id="@+id/fff"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_weight="9"        />    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_weight="1"        android:orientation="horizontal" >        <TextView            android:id="@+id/msg"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_weight="1"            android:gravity="center"            android:text="消息"            android:textSize="15sp" />        <TextView            android:id="@+id/contact"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_weight="1"            android:gravity="center"            android:text="联系人"            android:textSize="15sp" />        <TextView            android:id="@+id/activity"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_weight="1"            android:gravity="center"            android:text="动态"            android:textSize="15sp" />    </LinearLayout></LinearLayout>


package com.example.frangment;import android.app.Activity;import android.app.Fragment;import android.app.FragmentManager;import android.app.FragmentTransaction;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.widget.TextView;public class MainActivity extends Activity {private TextView message,contact,activity; private Fragmentmsg fsg;private Fragmentcontact fc;private Fragmentactivity fct;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);message = (TextView) findViewById(R.id.msg);contact = (TextView) findViewById(R.id.contact);activity = (TextView) findViewById(R.id.activity);fsg=new  Fragmentmsg();fc=new Fragmentcontact();fct=new Fragmentactivity();choice(0);message.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {choice(0);}});contact.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {choice(1);}});activity.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {choice(2);}});}private void choice(int i) {if (i == 0) {message.setTextColor(Color.BLUE);message.setBackgroundColor(Color.GREEN);contact.setTextColor(Color.LTGRAY);contact.setBackgroundColor(Color.WHITE);activity.setTextColor(Color.LTGRAY);activity.setBackgroundColor(Color.WHITE);loadfragement(fsg);}if (i == 1) {contact.setTextColor(Color.BLUE);contact.setBackgroundColor(Color.GREEN);message.setTextColor(Color.LTGRAY);message.setBackgroundColor(Color.WHITE);activity.setTextColor(Color.LTGRAY);activity.setBackgroundColor(Color.WHITE);loadfragement(fc);}if (i == 2) {activity.setTextColor(Color.BLUE);activity.setBackgroundColor(Color.GREEN);contact.setTextColor(Color.LTGRAY);contact.setBackgroundColor(Color.WHITE);message.setTextColor(Color.LTGRAY);message.setBackgroundColor(Color.WHITE);loadfragement(fct);}}private void loadfragement(Fragment f){FragmentManager fm=this.getFragmentManager();FragmentTransaction ft=fm.beginTransaction();ft.replace(R.id.fff, f);ft.commit();}}







更多相关文章

  1. listview中CheckBox的监听回调
  2. Android(安卓)自动向手机添加联系人(测试数据用)
  3. Android(安卓)动态设置布局文件的exception
  4. 动态生成控件
  5. android 实现ListView中添加RaidoButton单选
  6. 【黑马Android】(03)学生管理系统/动态刷新界面
  7. android之Handler控制进度条
  8. HandlerTest
  9. Aandroid 关于处理个推透传消息

随机推荐

  1. Android(安卓)Theme 熟悉的一点点
  2. Android(安卓)基础总结:(一)Android系统架构
  3. Android(安卓)4.4环境搭建——Android(安
  4. [原]如何在Android用FFmpeg+SDL2.0解码声
  5. android客户端与服务端交互的三种方式
  6. 不疯狂!非正常!
  7. [转]Android(安卓)SDK 中的 SDK Manager.
  8. 安卓表格布局android:collapseColumns,an
  9. Android应用程序启动过程源代码分析
  10. Android测试教程(2):测试基础