I have a custom title bar set on my TabActivity. The custom title bar contains a TextView and an ImageView in it. The tabHost has multiple tabs.
What I want to do is to access the ImageView resource in the tabs.
I am accessing the TextView from custom title bar in the main Tab activity (that extends TabActivity) and it is working fine. Following is the code which is working fine in main activity:
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);
Now I want to access the ImageView in my tabs (which are added in tabHost). If I set following code in tab:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
It gives following error:
You cannot combine custom titles with other title features
And if i directly set following in the tab code:
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mycustomtitle);
ImageView image = (ImageView) findViewById(R.id.imageTitleId);
The image remains null.
mycustomtitle.xml has following two elements:
<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>
Please give me some idea how can I access the Custom title’s ImageView in the tabs ?
You can access the
TextViewandImageViewby declaring thempublic staticin theTabActivity. Then, in theSub-Activityyou obviously access the public static TextView and ImageView like,