2011-09-23 15 views
17

私はアンドロイドアプリケーションを開発しました。以上、私は完了しましたが、私はオプションを最小限に抑えたい。私はタブバーを使いました。その中で私はタブを最小化したい。ユーザーが最小化タブをクリックすると、アプリケーション全体が最小限に抑えられます。 私のタブバーのコードは、このコードで..アンドロイドでアプリケーション全体を最小限に抑える方法は?

public class tabbar extends TabActivity implements OnTabChangeListener { 
    private Context mContext; 
    TabHost tabHost; 
    int tabload=0; 
    private AlertDialog alertDialog; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tabbar); 
     //mContext=this; 

     /** TabHost will have Tabs */ 
     tabHost = (TabHost)findViewById(android.R.id.tabhost); 
     tabHost.setOnTabChangedListener(this); 



     /** TabSpec used to create a new tab. 
     * By using TabSpec only we can able to setContent to the tab. 
     * By using TabSpec setIndicator() we can set name to tab. */ 

     /** tid1 is firstTabSpec Id. Its used to access outside. */ 
     TabSpec firstTabSpec = tabHost.newTabSpec("tab_id1"); 
     TabSpec secondTabSpec = tabHost.newTabSpec("tab_id2"); 
     TabSpec thirdTabSpec = tabHost.newTabSpec("tab_id3"); 


     /** TabSpec setIndicator() is used to set name for the tab. */ 
     /** TabSpec setContent() is used to set content for a particular tab. */ 
     firstTabSpec.setIndicator("FRIENDS").setContent(new Intent(this,view_friends.class)); 
     secondTabSpec.setIndicator("GROUPS").setContent(new Intent(this,groups.class)); 
     thirdTabSpec.setIndicator("SIGN OUT").setContent(new Intent(this,signout.class)); 


     /** Add tabSpec to the TabHost to display. */ 
     tabHost.addTab(firstTabSpec); 
     tabHost.addTab(secondTabSpec); 
     tabHost.addTab(thirdTabSpec); 



    } 



     @Override 
     public void onTabChanged(String tabId) { 
     // TODO Auto-generated method stub 

     for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
      { 
        tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#343333")); //unselected 
      } 
         tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#f1a026"));  // selected 
    //   if(tabId.equals("tab_id1")){ 
    //    LocalActivityManager manager = getLocalActivityManager(); 
    //    manager.destroyActivity("tab_id1", true); 
    //    manager.startActivity("tab_id1", new Intent(this, view_friends.class)); 
    //   } 

    } 
    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     tabHost.setCurrentTab(2); 
     System.gc(); 
    } 


} 

として任意の修正が...

は私のサンプルコードを与える助けてください必要がある場合..

+0

は、「最小化」の定義にアプリを非表示にしたい場合は、ホームボタンは十分以上ですが。あなたは['Activity.finish()'](http://developer.android.com/reference/android/app/Activity.html#finish())を探していますか? –

+0

あなたは今何をしたいですか?あなたは "ホーム"ボタンと同じ動作をしたいですか?それは本当に明らかではありません。 – Nanne

+0

はい私のタブのホームボタンの動作をクリックします – Selva

答えて

45

私はあなたが何を意味するかわからないんだけど最小化する。あなたがあなたのアプリを隠し、ホームスクリーンにユーザを提示したい場合は、以下のインテントを使用することができます。

Intent startMain = new Intent(Intent.ACTION_MAIN); 
startMain.addCategory(Intent.CATEGORY_HOME); 
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(startMain); 

ユーザーが

+0

これはまさに私が探していたものです。 – Derzu

+1

他のアプリケーションから最小化するには? – codezjx

関連する問題