我有一个包含操作栏和选项卡的布局:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout style="@style/BackgroundLayer">
<!-- Action Bar with buttons -->
<include layout="@layout/incl_actionbar"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
在操作栏上,我有几个按钮,我需要能够从选项卡内的活动中访问它们。但是 findViewById 为位于操作栏上的任何视图返回 null - 我觉得这很合乎逻辑,因为对于选项卡内的任何活动,它们的 contentRoot 是 FrameLayout (并且操作栏在它的旁边),但是我仍然需要访问操作栏,因为图标所有当前可用的操作都位于那里。
我还考虑过将操作栏作为选项卡内所有活动的额外意图传递,但 View 不是可序列化的,也不是 Parcelable,因此不能作为额外传递。