我正在尝试使用 [TabGroupChildDemo][1] 作为模板构建应用程序,但出现以下错误:
11-12 15:02:23.189: E/AndroidRuntime(699): FATAL EXCEPTION: main
11-12 15:02:23.189: E/AndroidRuntime(699): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lupradoa.lakari/com.lupradoa.lakari.Inicio_TabGroup}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.luisprado.lakari/com.luisprado.lakari.InicioActivityGroup}; have you declared this activity in your AndroidManifest.xml?
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.os.Handler.dispatchMessage(Handler.java:99)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.os.Looper.loop(Looper.java:137)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-12 15:02:23.189: E/AndroidRuntime(699): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 15:02:23.189: E/AndroidRuntime(699): at java.lang.reflect.Method.invoke(Method.java:511)
11-12 15:02:23.189: E/AndroidRuntime(699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-12 15:02:23.189: E/AndroidRuntime(699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-12 15:02:23.189: E/AndroidRuntime(699): at dalvik.system.NativeStart.main(Native Method)
11-12 15:02:23.189: E/AndroidRuntime(699): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.luisprado.lakari/com.luisprado.lakari.InicioActivityGroup}; have you declared this activity in your AndroidManifest.xml?
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:1870)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:285)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:694)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.widget.TabHost.setCurrentTab(TabHost.java:358)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.widget.TabHost.addTab(TabHost.java:236)
11-12 15:02:23.189: E/AndroidRuntime(699): at com.lupradoa.lakari.Inicio_TabGroup.onCreate(Inicio_TabGroup.java:68)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.Activity.performCreate(Activity.java:5008)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-12 15:02:23.189: E/AndroidRuntime(699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-12 15:02:23.189: E/AndroidRuntime(699): ... 11 more
我已经搜索了错误,更改了内容以检查活动是否显示(他们确实),检查了 Stackoverflow,互联网......没有结果。
应用程序 AndroidManifest (我试过删除包名,我得到了同样的错误。):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lupradoa.lakari"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.lupradoa.com.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.lupradoa.com.permission.MAPS_RECEIVE"/>
<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-feature android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxx"/>
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
<activity
android:name="com.lupradoa.lakari.SplashScreen"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.lupradoa.lakari.Inicio_TabGroup" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.lupradoa.lakari.Inicio" android:label="@string/app_name"/>
<activity android:name="com.lupradoa.lakari.Galeria" android:label="@string/app_name"/>
<activity android:name="com.lupradoa.lakari.Marcas" android:label="@string/app_name"/>
<activity android:name="com.lupradoa.lakari.Noticias" android:label="@string/app_name"/>
<activity android:name="com.lupradoa.lakari.InicioActivityGroup" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.lupradoa.lakari.MarcasActivityGroup" android:label="@string/app_name"/>
<activity android:name="com.lupradoa.lakari.GaleriaActivityGroup" android:label="@string/app_name"/>
<activity android:name="com.lupradoa.lakari.NoticiasActivityGroup" android:label="@string/app_name"/>
<activity android:name="com.lupradoa.lakari.BrandOneActivity" android:label="@string/app_name"/>
<activity android:name="com.lupradoa.lakari.BrandTwoActivity" android:label="@string/app_name"/>
</application>
</manifest>
闪屏:
package com.lupradoa.lakari;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import com.lupradoa.lakari.util.SystemUiHider;
/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
*
* @see SystemUiHider
*/
public class SplashScreen extends Activity {
/**
* Whether or not the system UI should be auto-hidden after
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
*/
private static final boolean AUTO_HIDE = true;
/**
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
* user interaction before hiding the system UI.
*/
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
/**
* If set, will toggle the system UI visibility upon interaction. Otherwise,
* will show the system UI visibility upon interaction.
*/
private static final boolean TOGGLE_ON_CLICK = true;
/**
* The flags to pass to {@link SystemUiHider#getInstance}.
*/
private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
/**
* The instance of the {@link SystemUiHider} for this activity.
*/
private SystemUiHider mSystemUiHider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
//launch app
Button go = (Button)findViewById(R.id.buttonGo);
go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent begin = new Intent (SplashScreen.this, Inicio_TabGroup.class);
startActivity(begin);
}
});
final View controlsView = findViewById(R.id.fullscreen_content_controls);
final View contentView = findViewById(R.id.fullscreen_content);
// Set up an instance of SystemUiHider to control the system UI for
// this activity.
mSystemUiHider = SystemUiHider.getInstance(this, contentView,
HIDER_FLAGS);
mSystemUiHider.setup();
mSystemUiHider
.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
// Cached values.
int mControlsHeight;
int mShortAnimTime;
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void onVisibilityChange(boolean visible) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
// If the ViewPropertyAnimator API is available
// (Honeycomb MR2 and later), use it to animate the
// in-layout UI controls at the bottom of the
// screen.
if (mControlsHeight == 0) {
mControlsHeight = controlsView.getHeight();
}
if (mShortAnimTime == 0) {
mShortAnimTime = getResources().getInteger(
android.R.integer.config_shortAnimTime);
}
controlsView
.animate()
.translationY(visible ? 0 : mControlsHeight)
.setDuration(mShortAnimTime);
} else {
// If the ViewPropertyAnimator APIs aren't
// available, simply show or hide the in-layout UI
// controls.
controlsView.setVisibility(visible ? View.VISIBLE
: View.GONE);
}
if (visible && AUTO_HIDE) {
// Schedule a hide().
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
}
});
// Set up the user interaction to manually show or hide the system UI.
contentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (TOGGLE_ON_CLICK) {
mSystemUiHider.toggle();
} else {
mSystemUiHider.show();
}
}
});
// Upon interacting with UI controls, delay any scheduled hide()
// operations to prevent the jarring behavior of controls going away
// while interacting with the UI.
findViewById(R.id.buttonGo).setOnTouchListener(
mDelayHideTouchListener);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Trigger the initial hide() shortly after the activity has been
// created, to briefly hint to the user that UI controls
// are available.
delayedHide(100);
}
/**
* Touch listener to use for in-layout UI controls to delay hiding the
* system UI. This is to prevent the jarring behavior of controls going away
* while interacting with activity UI.
*/
View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (AUTO_HIDE) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
Handler mHideHandler = new Handler();
Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
mSystemUiHider.hide();
}
};
/**
* Schedules a call to hide() in [delay] milliseconds, canceling any
* previously scheduled calls.
*/
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
}
Inicio_TabGroup,其中构建了选项卡和导航堆栈:
package com.lupradoa.lakari;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
import android.widget.TextView;
@SuppressWarnings("deprecation")
public class Inicio_TabGroup extends TabActivity implements OnTabChangeListener
{
private static final String[] TABS = { "InicioActivityGroup", "MarcasActivityGroup", "NoticiasActivityGroup","GaleriaActivityGroup" };
private static final String[] TAB_NAMES = { "Inicio", "Marcas", "Noticias","Galeria"};
public static TabHost tabs ;
public static TabWidget tabWidget ;
protected Bitmap roundedImage;
public boolean checkTabsListener = false;
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
Bitmap roundedImage = BitmapFactory.decodeResource(getResources(),R.drawable.ic_tab_background);
roundedImage = getRoundedCornerBitmap(roundedImage,3);
tabs = getTabHost();
tabWidget = tabs.getTabWidget();
tabs.setOnTabChangedListener(this);
for (int i = 0; i < TABS.length; i++)
{
TabHost.TabSpec tab = tabs.newTabSpec(TABS[i]);
//Asociating Components
ComponentName oneActivity = new ComponentName("com.luisprado.lakari", "com.luisprado.lakari." + TABS[i]);
Intent intent = new Intent().setComponent(oneActivity);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
tab.setContent(intent);
//Setting the Indicator
MyTabIndicator myTab = new MyTabIndicator(this, TAB_NAMES[i],(i+1), roundedImage);
tab.setIndicator(myTab);
tabs.addTab(tab);
}
checkTabsListener = true;
for(int i=0;i<tabs.getTabWidget().getChildCount();i++)
{
tabs.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
}
tabs.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.ic_tab_background);
//Maintaining Clicks
// Home Tab Click
tabWidget.getChildAt(0).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(InicioActivityGroup.InicioActivityStack != null && InicioActivityGroup.InicioActivityStack.mIdList.size()>1)
{
InicioActivityGroup.InicioActivityStack.getLocalActivityManager().removeAllActivities();
InicioActivityGroup.InicioActivityStack.mIdList.clear();
InicioActivityGroup.InicioActivityStack.mIntents.clear();
InicioActivityGroup.InicioActivityStack.mAnimator.removeAllViews();
InicioActivityGroup.InicioActivityStack.startChildActivity("ShopInfoActivity", new Intent(InicioActivityGroup.InicioActivityStack, Inicio.class));
}
tabWidget.setCurrentTab(0);
tabs.setCurrentTab(0);
tabs.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.ic_tab_background);
}
});
// Marcas tab Click
tabWidget.getChildAt(1).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if(MarcasActivityGroup.MarcasActivityStack != null && NoticiasActivityGroup.NoticiasActivityStack.mIdList.size()>0)
{
MarcasActivityGroup.MarcasActivityStack.getLocalActivityManager().removeAllActivities();
MarcasActivityGroup.MarcasActivityStack.mIdList.clear();
MarcasActivityGroup.MarcasActivityStack.mIntents.clear();
MarcasActivityGroup.MarcasActivityStack.mAnimator.removeAllViews();
MarcasActivityGroup.MarcasActivityStack.startChildActivity("TrackingGroupActivity", new Intent(MarcasActivityGroup.MarcasActivityStack, Marcas.class));
}
tabWidget.setCurrentTab(1);
tabs.setCurrentTab(1);
tabs.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.ic_tab_background);
}
});
// Noticias tab click
tabWidget.getChildAt(2).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if(NoticiasActivityGroup.NoticiasActivityStack != null && GaleriaActivityGroup.GaleriaActivityStack.mIdList.size()>0)
{
NoticiasActivityGroup.NoticiasActivityStack.getLocalActivityManager().removeAllActivities();
NoticiasActivityGroup.NoticiasActivityStack.mIdList.clear();
NoticiasActivityGroup.NoticiasActivityStack.mIntents.clear();
NoticiasActivityGroup.NoticiasActivityStack.mAnimator.removeAllViews();
NoticiasActivityGroup.NoticiasActivityStack.startChildActivity("NewsActivityGroup", new Intent(NoticiasActivityGroup.NoticiasActivityStack, Noticias.class));
}
tabWidget.setCurrentTab(2);
tabs.setCurrentTab(2);
tabs.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.ic_tab_background);
}
});
//Galeria tab click
tabWidget.getChildAt(3).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if(GaleriaActivityGroup.GaleriaActivityStack != null && GaleriaActivityGroup.GaleriaActivityStack.mIdList.size()>0)
{
GaleriaActivityGroup.GaleriaActivityStack.getLocalActivityManager().removeAllActivities();
GaleriaActivityGroup.GaleriaActivityStack.mIdList.clear();
GaleriaActivityGroup.GaleriaActivityStack.mIntents.clear();
GaleriaActivityGroup.GaleriaActivityStack.mAnimator.removeAllViews();
GaleriaActivityGroup.GaleriaActivityStack.startChildActivity("GalleryActivityGroup", new Intent(GaleriaActivityGroup.GaleriaActivityStack, Galeria.class));
}
tabWidget.setCurrentTab(3);
tabs.setCurrentTab(3);
tabs.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.ic_tab_background);
}
});
}
public class MyTabIndicator extends LinearLayout
{
public MyTabIndicator(Context context, String label, int tabId, Bitmap bgImg)
{
super(context);
LinearLayout tab = null;
TextView tv;
this.setGravity(Gravity.CENTER);
if(tabId == 1)
{
tab = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.inicio_tab, null);
tv = (TextView)tab.findViewById(R.id.tab_label);
tv.setText(label);
}
else if(tabId == 2)
{
tab = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.marcas_tab, null);
tv = (TextView)tab.findViewById(R.id.tab_label);
tv.setText(label);
}
else if(tabId == 3)
{
tab = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.noticias_tab, null);
tv = (TextView)tab.findViewById(R.id.tab_label);
tv.setText(label);
}
else if (tabId == 4)
{
tab = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.galeria_tab, null);
tv = (TextView)tab.findViewById(R.id.tab_label);
tv.setText(label);
}
this.addView(tab, new LinearLayout.LayoutParams(320/4,55));
}
}
public void onTabChanged(String tabId)
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(tabs.getApplicationWindowToken(), 0);
for(int i=0; i<tabs.getTabWidget().getChildCount(); i++)
{
if(tabId.equalsIgnoreCase(TABS[i]))
{
tabs.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.ic_tab_background);
}
else
{
tabs.getTabWidget().getChildAt(i).setBackgroundColor((Color.TRANSPARENT));
}
}
}
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap,float roundPxRadius)
{
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx =roundPxRadius;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
public void onResume()
{
super.onResume();
//ReConstructing TabViews
reDesignTabViews();
}
public void onPause()
{
super.onPause();
}
/**
* Method used to re constructing the Views at tab bar. This solves tabs disappearing issue.
*/
public void reDesignTabViews()
{
MyTabIndicator myIndicator;
//Construction of tab views....
for(int i=0 ; i< tabWidget.getChildCount() ; i++)
{
myIndicator = (MyTabIndicator) tabWidget.getChildAt(i);
myIndicator.removeAllViews();
switch (i)
{
case 0:
myIndicator.addView((LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.inicio_tab, null));
break;
case 1:
myIndicator.addView((LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.marcas_tab, null));
break;
case 2:
myIndicator.addView((LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.noticias_tab, null));
break;
case 3:
myIndicator.addView((LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.galeria_tab,null));
break;
}
}
}
}
此类打开 InicioActivityGroup 以控制通过显示选项卡的活动的导航。
package com.lupradoa.lakari;
import android.content.Intent;
import android.os.Bundle;
import com.lupradoa.lakari.util.AnimatedActivity;
public class InicioActivityGroup extends AnimatedActivity {
public static InicioActivityGroup InicioActivityStack;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
InicioActivityStack = InicioActivityGroup.this;
startChildActivity("InicioActivityGroup", new Intent(this, Inicio.class));
}
}
请你帮助我好吗?