如何从Activity调用TabAcitivity

时间:2014-05-15 13:37:58

标签: android-activity tabactivity setcontentview

d 我需要你的帮助。

我有一个活动(登录屏幕),她扩展了活动! 我的APP有3个标签,她扩展了TabActivity。 我需要用tabactivity编写这段代码(不建议使用)。 ; d

我的问题是:当我点击登录屏幕(活动)中的按钮时,我想调用我的活动(TabAcitivty),但是当我这样做时,只显示一个白色的屏幕= \

我的屏幕登录

public class TelaLogin extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_login);

        Button btnGoogle = (Button) findViewById(R.id.btn_google);
        btnGoogle.setOnClickListener(new View.OnClickListener() {
            @Override
            **public void onClick(View v) {
                Intent myIntent = new Intent(getApplicationContext(), TabBar.class);
                startService(myIntent);
                setContentView(R.layout.act_frag_tab_bar);
            }**
        });
    }
}

我的TabActivity

public class TabBar extends TabActivity implements OnTabChangeListener {
... The code is "Maceta"(Large)
}

R.layout.act_frag_tab_bar有我的3个标签。

2 个答案:

答案 0 :(得分:1)

package com.example.androidtablayout;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AndroidActivity extends Activity {

// button to show progress dialog
Button btnCallTabActivity;
Context con;

public static final int progress_bar_type = 0; 

// File url to download

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mains);
    con=this;
    // show progress bar button
    btnCallTabActivity = (Button) findViewById(R.id.btnTabActivity);
    // Image view to show image after downloading
    /**
     * Show Progress bar click event
     * */
    btnCallTabActivity.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i = new Intent(con, AndroidTabLayoutActivity.class);
            startActivity(i);
        }
    });
}
/**
 * Showing Dialog
 * */

}    
  

你的Tab Activity应该是这样的

package com.example.androidtablayout;

import android.app.TabActivity;

import android.content.Intent;

import android.os.Bundle;

import android.widget.TabHost;

import android.widget.TabHost.TabSpec;

public class AndroidTabLayoutActivity extends TabActivity {

/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TabHost tabHost = getTabHost();

    // Tab for Photos
    TabSpec photospec = tabHost.newTabSpec("Photos");
    photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
    Intent photosIntent = new Intent(this, PhotosActivity.class);
    photospec.setContent(photosIntent);

    // Tab for Songs
    TabSpec songspec = tabHost.newTabSpec("Songs");
    // setting Title and Icon for the Tab
    songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
    Intent songsIntent = new Intent(this, SongsActivity.class);
    songspec.setContent(songsIntent);

    // Tab for Videos
    TabSpec videospec = tabHost.newTabSpec("Videos");
    videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
    Intent videosIntent = new Intent(this, VideosActivity.class);
    videospec.setContent(videosIntent);

    // Adding all TabSpec to TabHost
    tabHost.addTab(photospec); // Adding photos tab
    tabHost.addTab(songspec); // Adding songs tab
    tabHost.addTab(videospec); // Adding videos tab
}
}

答案 1 :(得分:0)

我编辑了manifest.xml并添加了这些行:

<activity android:name="tcc.sigme.TabBar" >
</activity>
<activity android:name="tcc.sigme.Tab01" >
</activity>
<activity android:name="tcc.sigme.Tab02" >
</activity>
<activity android:name="tcc.sigme.Tab03" >
</activity>

你看到:https://github.com/EdilsonGalvao/SigMe/blob/master/SigME/AndroidManifest.xml

非常感谢。

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="tcc.sigme"
    android:versionCode="1"
    android:versionName="1.0" >

    <!-- Permission Uses Google Maps -->

    <uses-permission android:name="permission_name" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="19" />

    <!-- Unable OpenGL for run Maps -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

        <!-- Google API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCizmQT2lm48beRhFFa78kjEqoamFke9iM" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="tcc.sigme.TelaLogin"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <activity android:name="tcc.sigme.TabBar" >
        </activity>
        <activity android:name="tcc.sigme.Tab01" >
        </activity>
        <activity android:name="tcc.sigme.Tab02" >
        </activity>
        <activity android:name="tcc.sigme.Tab03" >
        </activity>
    </application>

</manifest>