在我的应用程序中使用Tab主机活动并设置带有图片的选项卡。当应用程序在模拟器上运行时,图像显示没有任何问题。但是当我在移动设备(Micromax mobile)上运行应用程序时,它并没有显示出来。
请告诉我问题是什么以及如何解决它。
选项卡主机编码:
Intent intent = new Intent(this, WeekActivity.class);
tabHost.addTab(tabHost
.newTabSpec("Week")
.setIndicator("Weekly", res.getDrawable(R.drawable.ic_tab_main))
.setContent(intent));
Intent intent2 = new Intent(this,ListMonthActivity.class);
tabHost.addTab(tabHost
.newTabSpec("Month")
.setIndicator("Monthly", res.getDrawable(R.drawable.ic_tab_setup))
.setContent(intent2));
tabHost.setCurrentTab(0);
Intent intent3 = new Intent(this, ListYearActivity.class);
TabHost.TabSpec spec=tabHost.newTabSpec("Year").setIndicator("Yearly",getResources().getDrawable(R.drawable.ic_launcher)).setContent(intent3);
tabHost.addTab(spec);
/*tabHost.addTab(tabHost
.newTabSpec("Year")
.setIndicator("Yearly", res.getDrawable(R.drawable.ic_tab_setup))
.setContent(intent3));
tabHost.setCurrentTab(0);*/
// Set tabs Colors
tabHost.setBackgroundColor(Color.BLACK);
tabHost.getTabWidget().setBackgroundColor(Color.BLACK);
}选择器选项卡主机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/calendaricon"
android:state_selected="true"/>
<!-- When not selected, use white-->
<item android:drawable="@drawable/calendaricon2" />
</selector>Tabhost布局XML文件:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="0dp"
>
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
/>
</LinearLayout>
</TabHost>发布于 2012-07-06 14:33:44
要么你必须保存每个文件夹中的图像,如mdpi,hdpi,ldpi的同名或你必须保存图片在mdpi文件夹中的低分辨率或高清晰度移动自动从mdpi文件夹中的图像。
发布于 2013-07-18 19:31:27
当我给出下面的代码时,它成功地工作了。
mTabHost.addTab(mTabHost.newTabSpec("Bar").setIndicator("",getResources().getDrawable(R.drawable.ic_barchart)), BarChart.class, null);我所做的更改是,简单地将setIndicator的第一个参数保留为空字符串。(当我将其作为"BarChart"时,它不起作用。)
发布于 2012-07-06 14:50:18
将选项卡主机中的图像设置为:
TabHost.TabSpec spec=tabHost.newTabSpec("hello").setIndicator("hello",getResources().getDrawable(R.drawable.ic_launcher)).setContent(intent);
tabHost.addTab(spec);我刚刚在这个设备上试了试,它工作得很好。
https://stackoverflow.com/questions/11356903
复制相似问题