关闭

微信界面

标签: 微信界面android
98人阅读 评论(0) 收藏 举报
分类:

MainActivity:

package com.example.fragmentwex;


import android.os.Bundle;
import android.app.Fragment;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity implements TextView.OnClickListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	
		TextView weixin=(TextView) findViewById(R.id.weixin);
		weixin.setOnClickListener(this);
	
		TextView tongxunlu=(TextView) findViewById(R.id.tongxunlu);
		tongxunlu.setOnClickListener(this);
		
		TextView faxian=(TextView) findViewById(R.id.faxian);
		faxian.setOnClickListener(this);
		
		TextView wo=(TextView) findViewById(R.id.wo);
		wo.setOnClickListener(this);
		
		load(new WeiXinFragment());
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.weixin:
			load(new WeiXinFragment());
			break;
			
		case R.id.tongxunlu:
			load(new TongXunLuFragment());
			break;
			
		case R.id.faxian:
			load(new FaXianFragment());
			break;
			
		case R.id.wo:
			load(new WoFragment());
			break;
			
		default:
			break;
		}	
		
	}
	
	private void load(Fragment f){
		FragmentManager fm = this.getFragmentManager();
		FragmentTransaction ft = fm.beginTransaction();
		ft.replace(R.id.fragment, f);
		ft.commit();
	}
	
}


微信:


package com.example.fragmentwex;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class WeiXinFragment extends Fragment{
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		View view = inflater.inflate(android.R.layout.simple_list_item_1,null);
		view.setBackgroundColor(Color.DKGRAY);
		return view;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		TextView text = (TextView) view.findViewById(android.R.id.text1);
		text.setText("微信");
	}

}


通讯录:


package com.example.fragmentwex;


import android.os.Bundle;
import android.app.Fragment;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class TongXunLuFragment extends	Fragment{

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		View view = inflater.inflate(android.R.layout.simple_list_item_1,null);
		view.setBackgroundColor(Color.GREEN);
		return view;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		TextView text = (TextView) view.findViewById(android.R.id.text1);
		text.setText("通讯录");
	}
}


发现:


package com.example.fragmentwex;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class FaXianFragment extends Fragment {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		View view = inflater.inflate(android.R.layout.simple_list_item_1,null);
		view.setBackgroundColor(Color.RED);
		return view;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		TextView text = (TextView) view.findViewById(android.R.id.text1);
		text.setText("发现");
	}
}


我:


package com.example.fragmentwex;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class WoFragment extends Fragment{

	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(android.R.layout.simple_list_item_1,null);
		view.setBackgroundColor(Color.YELLOW);
		return view;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		TextView text = (TextView) view.findViewById(android.R.id.text1);
		text.setText("我");
	}
}

布局:

<LinearLayout 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"
	android:orientation="vertical"
    tools:context="com.example.fragmentwex.MainActivity" >

    <FrameLayout
        android:id="@+id/fragment"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="9" 
        
        >

    </FrameLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:orientation="horizontal" 
        >
        
        <TextView
            android:id="@+id/weixin"
            android:background="#ffd400"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="微信" 
            android:gravity="center"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/tongxunlu"
            android:background="#f3715c"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="通讯录"
            android:gravity="center"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/faxian"
            android:background="#f391a9"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="发现" 
            android:gravity="center"
            android:layout_weight="1"/>
        
        <TextView
            android:id="@+id/wo"
            android:background="#f15a22"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="我" 
            android:gravity="center"
            android:layout_weight="1" 
            />
   
    </LinearLayout>

</LinearLayout>


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:20625次
    • 积分:1114
    • 等级:
    • 排名:千里之外
    • 原创:91篇
    • 转载:20篇
    • 译文:0篇
    • 评论:1条
    文章分类
    文章存档
    最新评论