1

私のアプリケーションでは、タブホストアクティビティを使用して、タブに画像を設定します。アプリケーションがエミュレーターで実行されている間、画像は問題なく表示されます。しかし、モバイル(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>

タブホストレイアウト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>
4

3 に答える 3

2

mdpi、hdpi、ldpiのような各フォルダーに同じ名前で画像を保存するか、画像をmdpiフォルダーに保存するだけで、低解像度または高密度のモバイルがmdpiフォルダーから画像を自動的に選択します..

于 2012-07-06T06:33:43.830 に答える
1

タブホストの画像を次のように設定します。

TabHost.TabSpec spec=tabHost.newTabSpec("hello").setIndicator("hello",getResources().getDrawable(R.drawable.ic_launcher)).setContent(intent);
tabHost.addTab(spec);

デバイスでこれを試したところ、正常に動作しました。

于 2012-07-06T06:50:17.907 に答える