2011-09-23 26 views
17

Tôi đã phát triển ứng dụng Android. Nhiều hơn tôi đã hoàn thành, nhưng tôi muốn giảm thiểu tùy chọn. Tôi đã sử dụng thanh tab. Trong đó tôi muốn giảm thiểu tab. Khi người dùng nhấp vào tab thu nhỏ để giảm thiểu toàn bộ ứng dụng. mã của tôi thanh tabbar như ..Làm thế nào để giảm thiểu toàn bộ ứng dụng trong Android?

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(); 
    } 


} 

Trong mã này nếu có nhu cầu sửa chữa xin vui lòng giúp đỡ ...

cho tôi một mẫu mã ..

+0

Xác định "giảm thiểu". Bạn đang tìm kiếm ['Activity.finish()'] (http://developer.android.com/reference/android/app/Activity.html#finish())? –

+0

Bạn muốn gì bây giờ? Bạn muốn có hành vi tương tự như nút "home"? Nó không thực sự rõ ràng. – Nanne

+0

vâng tôi muốn hành vi nút trang chủ trong tab của tôi nhấp vào – Selva

Trả lời

45

Tôi không chắc chắn những gì bạn có ý nghĩa bởi giảm thiểu. Nếu bạn muốn ẩn ứng dụng của mình và trình bày người dùng bằng màn hình chính, bạn có thể sử dụng ý định sau.

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

Mặc dù nút Home là đầy đủ hơn nếu người dùng muốn để ẩn ứng dụng của bạn

+0

Đó chính xác là những gì tôi đang tìm kiếm. – Derzu

+1

Cách giảm thiểu từ ứng dụng khác? – codezjx

Các vấn đề liên quan