Android tabview图标无法显示

时间:2015-10-07 00:41:49

标签: android-tabs

enter image description here

Tabbar图标未显示

我尝试更改res.getDrawble(R.drawble.ic_alarm)但未显示。

我使用Fragment/ViewPager,因此请FakeContent

tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec tabSpec;
Resources res = getResources();

tabSpec = tabHost.newTabSpec("Tab1");
tabSpec.setIndicator("Tab1", res.getDrawable(R.drawable.alarm));
tabSpec.setContent(new FakeContent(getApplicationContext()));
tabHost.addTab(tabSpec);

tabSpec = tabHost.newTabSpec("Tab2");
tabSpec.setIndicator("Tab2", getResources().getDrawable(R.drawable.ic_alarm));
tabSpec.setContent(new FakeContent(getApplicationContext()));
tabHost.addTab(tabSpec);

tabSpec = tabHost.newTabSpec("Tab3");
tabSpec.setIndicator("Tab3",getResources().getDrawable(R.drawable.ic_alarm));
tabSpec.setContent(new FakeContent(getApplicationContext()));
tabHost.addTab(tabSpec);

tabHost.setOnTabChangedListener(this);

XML ic_alarm

 <?xml version="1.0" encoding="utf-8"?>
     <selector xmlns:android="http://schemas.android.com/apk/res/android">
         <item android:drawable="@drawable/alarm" android:state_selected="true" />
     </selector>

0 个答案:

没有答案