android - 标签主机中不显示图像

标签 android image android-tabhost

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

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

选项卡主机编码:

        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>

最佳答案

要么你必须将图像保存在每个文件夹中,如 mdpi、hdpi、ldpi 具有相同的名称,要么你必须将图片保存在 mdpi 文件夹中,低分辨率或高密度移动设备会自动从 mdpi 文件夹中选择图像。

关于android - 标签主机中不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11356903/

相关文章:

android - Android 平台上的 Phonegap 应用 - 保持应用运行

java - Android 中的线程 UI 更新

java - Android 将 Recyclerview 复选框中的值发送到数据库

image - emacs 24.4.1 图像支持 - 找不到 libpng16.dll 二进制文件

python - 如何在Python中随机化图像像素

Android - 选项卡作为 Activity 的一部分

java - 带有固定选项卡的操作栏

android - 如何以编程方式设置标题

python - 将 Canvas 图像中的图像保存到 Django 文件夹中

java - Android:使用 TabHost 和 TabWidget 自定义选项卡的外观