Android Faux QQ Messaging Interface

Source: Internet
Author: User

Values below

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= "Message"
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= "Phone"
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>

Two x 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= "Message Interface"
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

}
}
};

}

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 {

@Override
Public View Oncreateview (Layoutinflater inflater,
ViewGroup container, Bundle savedinstancestate) {

Return inflater.inflate (r.layout.fragment_message, NULL);
}

}

Android Faux QQ Messaging Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.