【发布时间】:2011-10-14 13:11:38
【问题描述】:
我在 TabActivity 上设置了自定义标题栏。自定义标题栏包含一个 TextView 和一个 ImageView。 tabHost 有多个标签。
我要做的是访问选项卡中的 ImageView 资源。
我正在从主 Tab 活动(扩展 TabActivity)中的自定义标题栏访问 TextView,它工作正常。以下是在主要活动中运行良好的代码:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.myactivity);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mycustomtitle);
TextView tv = (TextView) findViewById(R.id.viewTitleId);
现在我想在我的选项卡(已添加到 tabHost)中访问 ImageView。如果我在选项卡中设置以下代码:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
它给出以下错误:
You cannot combine custom titles with other title features
如果我直接在标签代码中设置以下:
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mycustomtitle);
ImageView image = (ImageView) findViewById(R.id.imageTitleId);
图像保持为空。
mycustomtitle.xml 有以下两个元素:
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.80"
android:id="@+id/viewTitleId"
android:textColor="@color/titleBarTextColor"
android:gravity="center_vertical"
android:text="@string/viewText"
android:textSize="18px"
android:paddingLeft="45px"
/>
<ImageView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.20"
android:src="@drawable/btn_save"
android:id="@+id/imageTitleId"
>
</ImageView>
请告诉我如何在选项卡中访问自定义标题的 ImageView?
【问题讨论】:
标签: java android android-tabhost tabactivity