【发布时间】:2011-05-11 12:53:15
【问题描述】:
我有一个包含操作栏和选项卡的布局:
<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 (并且操作栏在它的旁边),但是我仍然需要访问操作栏,因为图标所有当前可用的操作都位于那里。
我还考虑过将 actionbar 作为额外的选项卡传递给选项卡内的所有活动,但 View 不是可序列化的也不是 Parcelable,因此不能作为额外的传递。
【问题讨论】:
标签: android android-tabhost tabwidget android-actionbar