2017-02-23 36 views
0

下面的代碼是從mainactivity但似乎已經閱讀在網絡上每一個崗位 - 但仍然無法找到一個例子,以幫助...仍然不能得到圖標上TabHost(HELP ...)

我想要的圖標相對於在tabhost

TabHost tabHost =(TabHost)findViewById(android.R.id.tabhost); 
TabSpec tab1=tabHost.newTabSpec("First Tab"); 
TabSpec tab2=tabHost.newTabSpec("Second Tab"); 
TabSpec tab3=tabHost.newTabSpec("Third Tab"); 

tabHost.addTab(tabHost.newTabSpec("Your Tab") 
      .setIndicator("Login") 
      .setContent(new Intent(this, Tab1Activity.class) 
      .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); 


tabHost.addTab(tabHost.newTabSpec("Your Tab") 
      .setIndicator("Fare(s)") 
      .setContent(new Intent(this, Tab2Activity.class) 
      .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); 

tabHost.addTab(tabHost.newTabSpec("Your Tab") 
      .setIndicator("Info") 
      .setContent(new Intent(this, Tab3Activity.class) 
      .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); 

}文本

回答

0

嘗試以下

tabHost.getTabAt(0).setIcon(getResources().getDrawable(R.mipmap.icon4)); 
tabHost.getTabAt(1).setIcon(getResources().getDrawable(R.mipmap.icon3)); 
tabHost.getTabAt(2).setIcon(getResources().getDrawable(R.mipmap.icon2)); 
tabHost.getTabAt(3).setIcon(getResources().getDrawable(R.mipmap.icon1)); 
//Please note that R.mipmap.* stands for your icons storage location, it can be drawable or any other folder 
+0

方法getTabAt(INT)是未定義的鍵入TabHost –

+0

爲什麼不使用'TabLayout'而不是'TabHost'我認爲標籤圖標是用''TabLayout'引入的,並且與'TabHost'不兼容,如果你想切換我可以幫你使用代碼 –

相關問題