Android ActivityGroup usage

Source: Internet
Author: User
Tags set background

Code Section:

<? 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"> <LinearLayout android: gravity = "center_horizontal" android: layout_width = "fill_parent" android: layout_height = "wrap_content"> <TextView android: id = "@ + id/cust_title" android: layout_width = "wrap_content" android: layout_height = "wr Ap_content "android: textColor =" @ android: color/white "android: textSize =" 18sp "/> </LinearLayout> <! -- Dynamically load view in the middle --> <ScrollView android: id = "@ + id/containerBody" android: layout_width = "fill_parent" android: layout_height = "300dip"> </ScrollView> <LinearLayout android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_gravity = "bottom" android: orientation = "horizontal"> <! -- Function module 1 --> <ImageView android: id = "@ + id/btnModule1" android: src = "@ android: drawable/ic_dialog_dialer" android: layout_marginLeft = "7dip" android: layout_marginTop = "3dip" android: layout_marginBottom = "3dip" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> <! -- Function module 2 --> <ImageView android: id = "@ + id/btnModule2" android: src = "@ android: drawable/ic_dialog_info" android: layout_marginLeft = "7dip" android: layout_marginTop = "3dip" android: layout_marginBottom = "3dip" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> <! -- Function module button 3 --> <ImageView android: id = "@ + id/btnModule3" android: src = "@ android: drawable/ic_dialog_alert" android: layout_marginLeft = "7dip" android: layout_marginTop = "3dip" android: layout_marginBottom = "3dip" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </LinearLayout>
package com.yek;import android.app.ActivityGroup;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageView;import android.widget.ScrollView;import android.widget.TextView;public class LearnActivity extends ActivityGroup implements OnClickListener{        private TextView title;    private ScrollView contain;    private ImageView btnOne;    private ImageView btnTwo;    private ImageView btnThree;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_group_layout);        initView();        setListener();    }        private void initView(){        title = (TextView)findViewById(R.id.cust_title);        contain = (ScrollView)findViewById(R.id.containerBody);        btnOne = (ImageView)findViewById(R.id.btnModule1);        btnTwo = (ImageView)findViewById(R.id.btnModule2);        btnThree = (ImageView)findViewById(R.id.btnModule3);    }        private void setListener(){        btnOne.setOnClickListener(this);        btnTwo.setOnClickListener(this);        btnThree.setOnClickListener(this);            }    @Override    public void onClick(View v) {        switch (v.getId()) {        case R.id.btnModule1:            btnOneListener(ModuleView1.class);            break;        case R.id.btnModule2:            btnOneListener(ModuleView2.class);            break;        case R.id.btnModule3:            btnOneListener(ModuleView3.class);            break;        }    }        private void btnOneListener(Class clazz){        contain.removeAllViews();        View view = getLocalActivityManager().startActivity("Module1", new Intent(this,clazz).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();        contain.addView(view);    }    }
<?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" >    <TextView        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:text="@string/hello"         android:id="@+id/content"        />    </LinearLayout>
Package com. yek; import android. app. activity; import android. OS. bundle; import android. widget. textView; public class ModuleBaseActivity extends Activity {private TextView content; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); content = (TextView) findViewById (R. id. content);}/*** set content * @ param str */public void setContentText (String str) {content. setText (str);}/*** Set background color * @ param colorId */public void setBackground (int colorId) {content. setBackgroundColor (colorId );}}
Package com. yek; import android. graphics. color; import android. OS. bundle; public class ModuleView1 extends ModuleBaseActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setBackground (Color. RED); setContentText ("Module 1 ");}}
Package com. yek; import android. graphics. color; import android. OS. bundle; public class ModuleView2 extends ModuleBaseActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setBackground (Color. GREEN); setContentText ("module 2 ");}}
Package com. yek; import android. graphics. color; import android. OS. bundle; public class ModuleView3 extends ModuleBaseActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setBackground (Color. BLUE); setContentText ("module 3 ");}}

 

Related Article

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.