现在我正在尝试让选项卡布局正常工作。我已经像在 Android TabView 教程中一样完成了所有操作,应用程序运行正常,但问题是我没有看到我在 ic_tab_artists.xml 中定义的任何图标。只有文字。
我想这与默认主题或样式或其他主题有关。我试图更改它,但它根本没有帮助,仍然只是一条文本。
我使用的是 Android SDK v4.03。
我确信有足够多的 Android 高手可以提供帮助,在此先致谢。
这是我使用图标定义的 .xml:
?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/ic_tab_artists_grey"
android:state_selected="true" />
<!-- When not selected (default), use white-->
<item android:drawable="@drawable/ic_tab_artists_white" />
</selector>
我的主要 HolePage Activity :
@SuppressWarnings("deprecation")
public class HolePage extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hole_page);
//TABS
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable 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, HolePageScores.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("scores").setIndicator("Scores",
res.getDrawable(R.drawable.tab_scores_icons))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs - Info
intent = new Intent().setClass(this, HolePageInfo.class);
spec = tabHost.newTabSpec("info").setIndicator("Info",
res.getDrawable(R.drawable.tab_scores_icons))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs - Top
intent = new Intent().setClass(this, HolePageTop.class);
spec = tabHost.newTabSpec("top").setIndicator("Top",
res.getDrawable(R.drawable.tab_scores_icons))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs - Hole
intent = new Intent().setClass(this, HolePageHole.class);
spec = tabHost.newTabSpec("hole").setIndicator("Hole",
res.getDrawable(R.drawable.tab_scores_icons))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs - Par
intent = new Intent().setClass(this, HolePagePar.class);
spec = tabHost.newTabSpec("par").setIndicator("Par",
res.getDrawable(R.drawable.tab_scores_icons))
.setContent(intent);
tabHost.addTab(spec);
//Set default tab2
tabHost.setCurrentTab(1);
}
}
最佳答案
在对主题了解不多的情况下,我发现在应用程序 list 中指定主题 @android:style/Theme.NoTitleBar
可以解决问题,并且图标会显示在选项卡中。
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
>
<!-- MANIFEST -->
</application>
希望对您有所帮助!
关于android Tab 图标不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9225868/