Android仿QQ消息导航UI

1.layout_im_switch.xml文件部分
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
	android:id="@+id/btn_header"
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="wrap_content">

	<LinearLayout
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_centerInParent="true"
		android:background="@drawable/im_switch_bg"
		android:padding="1dp">

		<RelativeLayout
			android:id="@+id/layout_family"
			android:layout_width="74dip"
			android:layout_height="match_parent">

			<Button
				android:id="@+id/btn_family"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:background="@android:color/transparent"
				android:gravity="center"
				android:singleLine="true"
				android:layout_centerInParent="true"
				android:text="家庭群"
				android:textColor="#03a9f4"
				android:textSize="14sp"/>

			<ImageView
				android:id="@+id/family_red_point"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:layout_alignTop="@+id/btn_family"
				android:layout_toRightOf="@+id/btn_family"
				android:paddingTop="3dp"
				android:src="@drawable/im_item_red_point"
				android:visibility="visible"/>
		</RelativeLayout>

		<RelativeLayout
			android:id="@+id/layout_baby"
			android:layout_width="74dip"
			android:layout_height="match_parent"
			android:background="@drawable/im_baby">

			<Button
				android:id="@+id/btn_baby"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:background="@android:color/transparent"
				android:gravity="center"
				android:layout_centerInParent="true"
				android:singleLine="true"
				android:text="宝贝宝贝"
				android:textColor="#ffffff"
				android:textSize="14sp"/>

			<ImageView
				android:id="@+id/baby_red_point"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:layout_alignTop="@+id/btn_baby"
				android:layout_toRightOf="@+id/btn_baby"
				android:paddingTop="3dp"
				android:src="@drawable/im_item_red_point"
				android:visibility="visible"/>
		</RelativeLayout>
	</LinearLayout>
</RelativeLayout>

2.java文件code

	private View mTitleSwitchView = null;
	private View mLayoutFamily, mLayoutBaby;
	private Button mBtnFamily, mBtnBaby;
	private ImageView mFamilyRedPoint, mBabyRedPoint;

       <pre name="code" class="java">	mTitleSwitchView = mLayoutInflater.inflate(R.layout.layout_im_switch, null);
	mLayoutFamily = mTitleSwitchView.findViewById(R.id.layout_family);
	mLayoutBaby = mTitleSwitchView.findViewById(R.id.layout_baby);
	mFamilyRedPoint = (ImageView) mTitleSwitchView.findViewById(R.id.family_red_point);
	mBabyRedPoint = (ImageView) mTitleSwitchView.findViewById(R.id.baby_red_point);
	mBtnFamily = (Button) mTitleSwitchView.findViewById(R.id.btn_family);
	mBtnBaby = (Button) mTitleSwitchView.findViewById(R.id.btn_baby);
	mBtnFamily.setOnClickListener(this);
	mBtnBaby.setOnClickListener(this);

 
  
 
	@Override
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.btn_family:
				mBtnFamily.setTextColor(Color.parseColor("#03a9f4"));
				mLayoutFamily.setBackgroundColor(Color.TRANSPARENT);
				mBtnBaby.setTextColor(Color.parseColor("#ffffff"));
				mLayoutBaby.setBackgroundResource(R.drawable.im_baby);
				break;
			case R.id.btn_baby:
				mBtnBaby.setTextColor(Color.parseColor("#03a9f4"));
				mLayoutBaby.setBackgroundColor(Color.TRANSPARENT);
				mBtnFamily.setTextColor(Color.parseColor("#ffffff"));
				mLayoutFamily.setBackgroundResource(R.drawable.im_family);
				break;
		}
	}

你可能感兴趣的:(android,QQ消息导航Switch)