首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >选项卡主机中未显示的图像

选项卡主机中未显示的图像
EN

Stack Overflow用户
提问于 2012-07-06 14:24:07
回答 3查看 4.1K关注 0票数 1

在我的应用程序中使用Tab主机活动并设置带有图片的选项卡。当应用程序在模拟器上运行时,图像显示没有任何问题。但是当我在移动设备(Micromax mobile)上运行应用程序时,它并没有显示出来。

请告诉我问题是什么以及如何解决它。

选项卡主机编码:

代码语言:javascript
复制
        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文件

代码语言:javascript
复制
  <?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文件:

代码语言:javascript
复制
   <?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>
EN

回答 3

Stack Overflow用户

发布于 2012-07-06 14:33:44

要么你必须保存每个文件夹中的图像,如mdpi,hdpi,ldpi的同名或你必须保存图片在mdpi文件夹中的低分辨率或高清晰度移动自动从mdpi文件夹中的图像。

票数 2
EN

Stack Overflow用户

发布于 2013-07-18 19:31:27

当我给出下面的代码时,它成功地工作了。

代码语言:javascript
复制
mTabHost.addTab(mTabHost.newTabSpec("Bar").setIndicator("",getResources().getDrawable(R.drawable.ic_barchart)), BarChart.class, null);

我所做的更改是,简单地将setIndicator的第一个参数保留为空字符串。(当我将其作为"BarChart"时,它不起作用。)

票数 2
EN

Stack Overflow用户

发布于 2012-07-06 14:50:18

将选项卡主机中的图像设置为:

代码语言:javascript
复制
TabHost.TabSpec spec=tabHost.newTabSpec("hello").setIndicator("hello",getResources().getDrawable(R.drawable.ic_launcher)).setContent(intent);
tabHost.addTab(spec);

我刚刚在这个设备上试了试,它工作得很好。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11356903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档