如何在Android的标签栏中添加图标?
作者:互联网
目前,我正在Android应用程序中工作,使用TabHost设置五个选项卡,然后我尝试在选项卡栏中添加图标,但我不知道如何设置它?请帮我
提前致谢
我试过这里提到的供您参考:
//firstTab.setIcon(R.drawable.help);
//firstTab.setIconSelected(R.drawable.help_selected);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("1").setContent(new Intent(this, First.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("2").setContent(new Intent(this, Second.class)));
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("3").setContent(new Intent(this, Third.class)));
tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator("4").setContent(new Intent(this, Fourth.class)));
tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("5").setContent(new Intent(this, Fifth.class)));
tabHost.setCurrentTab(2);
解决方法:
使用重载的setIndicator()方法,该方法也接受Drawable参数:
tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("5", YOUR_DRAWABLE).setContent(new Intent(this, Fifth.class)));
例:
tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("5", getResources().getDrawable(android.R.drawable.arrow_down_float)).setContent(new Intent(this, Fifth.class)));
标签:icons,android-tabhost,android 来源: https://codeday.me/bug/20191127/2076395.html