【问题标题】:put a picture on tabHost在 tabHost 上放一张图片
【发布时间】:2012-06-12 09:20:02
【问题描述】:

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

    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));

但是程序崩溃了……

【问题讨论】:

  • 请分享任何图片。你想展示什么??
  • 图片是“book.png”,包含在 res 中,目前看到的伴随着单词“tab 1”
  • 你只想显示图片吗
  • tabHost.addTab(tabHost.newTabSpec("Tab 1").setContent(R.id.tab1) .setIndicator("",getResources().getDrawable(R.drawable.book))) ;
  • 我试过了,但下面还是空白:)

标签: android android-layout


【解决方案1】:

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

How to change the Tabs Images in the TabHost

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2013-08-16
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2017-10-19
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多