内的自定义标题栏上的findViewById我在我的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);
现在我想访问我的选项卡中的ImageView(它们被添加到tabHost中)。如果我设置在标签下面的代码:
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的?
这对我有用:)谢谢Lalit – rizzz86
这真的是一个糟糕的建议。请停止为SO用户创建内存泄漏。 – Reno
嗨雷诺心灵知道为什么有内存泄漏? – ericlee