2013-10-10 70 views
0

我想要做一個簡單的標籤應用程序在Android與四個選項卡選項卡。我的問題是,當我要顯示的圖標和指標,它只是只顯示文本的指標,我希望顯示tabhost繪製和指示燈的文字,這是我的代碼:android:無法顯示指標文本和tabhost上繪製

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     //hide title bar 
       BasicDisplaySettings.toggleTaskBar(SimasCardMainActivity.this, false); 
       //show status bar 
       BasicDisplaySettings.toggleStatusBar(SimasCardMainActivity.this, true); 

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

     Resources res = getResources(); // Resource object to get Drawables 
     TabHost tabHost = getTabHost(); // The activity TabHost 
     TabHost.TabSpec spec; // Resusable TabSpec for each tab 
     Intent intent; // Reusable Intent for each tab 

     // Create an Intent to launch an Activity for the tab (to be reused) 
     intent = new Intent().setClass(this, TerbaruSimasCard.class); 
     spec = tabHost.newTabSpec("Terbaru").setIndicator("Terbaru", 
        res.getDrawable(R.drawable.menu_terbaru)) 
        .setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, MerchantSimasCard.class); 
     spec = tabHost.newTabSpec("Merchant").setIndicator("Merchant", 
        res.getDrawable(R.drawable.menu_merchant)) 
        .setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, TentangSimasCard.class); 
     spec = tabHost.newTabSpec("Tentang").setIndicator("Tentang", 
        res.getDrawable(R.drawable.menu_tentang)) 
        .setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, FaqSimasCard.class); 
     spec = tabHost.newTabSpec("FAQ").setIndicator("FAQ", 
        res.getDrawable(R.drawable.menu_faq)) 
        .setContent(intent); 
     tabHost.addTab(spec); 


     for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++){ 
      tabHost.getTabWidget().getChildAt(i).setPadding(0,0,0,0); 
      tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null); 
     } 
     tabHost.setCurrentTab(0); 
    } 

// @Override 
    public void onBackPressed() { 
    finish(); 
    } 

當我使用

spec = tabHost.newTabSpec("Tentang").setIndicator("", 
         res.getDrawable(R.drawable.menu_tentang)) 
         .setContent(intent); 

它會顯示一個圖標,但當我在setIndicatorsetIndicator("Tentang")上添加文本時,它只顯示tabhost上的指示符文本,我不知道我的代碼出了什麼問題,我試圖獲得增加標籤高度,但它不起作用,我希望有人能幫我解決我的問題。謝謝

回答

0

刪除此tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null);

tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.menu_tentang); 

我已經做了這樣的替換它,它工作正常

Resources ressources = getResources(); 
    TabHost tabHost = getTabHost(); 

    Intent addfriend = new Intent().setClass(this, yourclass1.class); 
    Intent mailfriend = new Intent().setClass(this, yourclass2.class); 
    tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.youpng)).setContent(addfriend)); 
    tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.yourpng)).setContent(mailfriend)); 



    tabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.anycolor)); 
    tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.yourpng); 

    tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.anycolor)); 
    tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.youpng); 
+0

嚴重?我不認爲它會起作用.... –

+0

@AoyamaNanami看我的編輯 –