不用tabWidget,实现全局菜单,切换不同activity

入口Activity

 

1、布局

 

<?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" >
  

    <ScrollView
        android:id="@+id/containerBody"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:measureAllChildren="true" >
    </ScrollView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@android:color/black"
        android:orientation="horizontal" >

       

        <TextView
            android:id="@+id/btn_main"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="7dp"
            android:layout_marginTop="3dp"
            android:text="主页" />
      

        <TextView
            android:id="@+id/btn_record"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="7dp"
            android:layout_marginTop="3dp"
            android:text="我的录制" />
      

        <TextView
            android:id="@+id/btn_songs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="7dp"
            android:layout_marginTop="3dp"
            android:text="我的点歌" />
    </LinearLayout>

</LinearLayout>

 

 

2、代码

 

package com.chen.menu;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

public class MenuBarActivity extends ActivityGroup {
 
  private ScrollView container = null;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         setContentView(R.layout.menu_bar);

         container = (ScrollView) findViewById(R.id.containerBody);
        
         //默认加载主页面
         container.removeAllViews();
            container.addView(getLocalActivityManager().startActivity(
                    "main",
                    new Intent(MenuBarActivity.this, MainActivity.class)
                            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                    .getDecorView());
           
           
       
         TextView btnModule1 = (TextView) findViewById(R.id.btn_main);
         btnModule1.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
                 container.removeAllViews();
                 container.addView(getLocalActivityManager().startActivity(
                         "main",
                         new Intent(MenuBarActivity.this, MainActivity.class)
                                 .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                         .getDecorView());
             }
         });

        
         TextView btnModule2 = (TextView) findViewById(R.id.btn_record);
         btnModule2.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
                 container.removeAllViews();
                 container.addView(getLocalActivityManager().startActivity(
                         "record",
                         new Intent(MenuBarActivity.this, RecordActivity.class)
                                 .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                         .getDecorView());
             }
         });

       
         TextView btnModule3 = (TextView) findViewById(R.id.btn_songs);
         btnModule3.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
                 container.removeAllViews();
                 container.addView(getLocalActivityManager().startActivity(
                         "songs",
                         new Intent(MenuBarActivity.this, SongsActivity.class)
                                 .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                         .getDecorView());
             }
         });
     }

}

你可能感兴趣的:(android,layout,null,Class,encoding)