0

我實現了我的Android應用程序的初始屏幕....並且在我的操作欄中有一個自定義主頁按鈕,單擊時它將被重定向到我的控制面板活動,而不是我的閃屏......你有什麼想法如何實現它?我對於Android應用新手...單擊主頁按鈕時的Android默認屏幕

請告訴我該怎麼辦it..I不能得到任何想法如何代碼吧...

任何響應都非常appreciated..Thanks

我的菜單碼

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 

    switch (item.getItemId()) { 
    case R.id.menuitem1: 
      //code to be inserted here but I dont know how 
     break; 
    case R.id.menuitem2: 
     Log.i("This is Menu", "0"); 
     super.onBackPressed(); 

     break; 

    default: 
     break; 
    } 

    return true; 
} 

我的Android清單

<activity android:name=".SplashScreen" 
       android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" 

        > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".AndroidTabLayoutActivity" 
      android:logo="@drawable/logo" 
      android:label="" 
      > 
      <intent-filter> 
       <action android:name="com.droidnova.android.splashscreen.AndroidTabLayoutActivity" /> 
       <category android:name="android.intent.category.HOME" /> 
       <category android:name="android.intent.category.DEFAULT" /> 

      </intent-filter> 
     </activity> 

回答

0

你可以只使用startActivity(<Intent for your dashboard activity>)而不是super.onBackPressed()

在home鍵啓動儀表盤活動的OnClick
+0

我在我的Android應用程序中使用片段... – 2012-07-09 08:21:44

+0

然後只是將片段更改爲儀表板片段。如果你只是調用'super.onBackPressed()',那麼你以前的活動將被帶到前面。無法保證,它是您的儀表板。 – 2012-07-09 08:32:45

0

home.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      Intent intent=new Intent(currentclass.this,dashboardactivity.class); 
       startActivity(intent); 
       finish(); 
     } 
    }); 
+0

我的主頁按鈕是一個操作欄中的按鈕,所以最好,我會去插入它menuitem1的情況。我的儀表板是一個在AndroidTablayoutActivity.class中調用的片段 – 2012-07-09 08:43:02

0

你說的儀表盤是在你的AndroidTabLayoutActivity片段。我假設你不想從你當前的活動中調用這個片段。

你可以像這樣在打開AndroidTabLayoutActivity的意圖中傳遞一個參數。 (此代碼放在了onOptionsItemSelected()方法)

Intent intent = new Intent(); 
intent.setClass(this,AndroidTabLayoutActivity.class); 
intent.putExtra("type","dashboard"); 
startActivity(intent); 

然後在AndroidTabLayoutActivity在onCreate方法,你可以檢查,如果該參數存在。

if (getIntent().getStringExtra("type","splash").equals("dashboard")) { 
//start dashboard 
} else { 
    //start splashscreen 
}