0

我创建了一个主机选项卡,我只会将图像放在选项卡上。我找到了这个方法:

    tabHost.addTab(tabHost.newTabSpec("Tab 1").setContent(R.id.tab1)
            .setIndicator("Tab 1",getResources().getDrawable(R.drawable.book)));

提供文本和图像,但没有好处。我应该怎么做?

编辑

我尝试放入 main.xml:

                   <LinearLayout
                        android:id="@+id/tab1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <ImageView 
                            android:id="@+id/x2"
                            android:src="@drawable/book"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" />



                    </LinearLayout>

我在活动中添加了以下声明:

    tabHost.addTab(tabHost.newTabSpec("Tab 1").setContent(R.id.tab1));

但是程序崩溃了...

4

1 回答 1

1

我已经四处寻找与您的问题相关的类似问题,我认为如果您查看以下问题中提供的答案,您可能会找到一些对您有所帮助的答案:

如何更改 TabHost 中的选项卡图像

希望这可以帮助。

于 2012-06-12T09:32:40.720 回答