1

アクションバーとタブを含むレイアウトがあります。

<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であるため(そしてアクションバーはその側にあります)、これは非常に論理的ですが、それでもアクションバーへのアクセスが必要です。現在利用可能なすべてのアクションがそこにあります。

また、アクションバーをタブ内のすべてのアクティビティのインテントに追加として渡すことも考えましたが、ビューはシリアル化もパーセル化もできないため、追加として渡すことはできません。

4

2 に答える 2

2

TabActivityにアクションバーへのアクセスを提供させます。子アクティビティは、次のコードを使用してアクションバーをリクエストする必要があります。例:

View actionBar = ((CustomTabActivity) getParent()).getActionBar();
于 2011-05-11T13:07:22.930 に答える
0

アクションバービューが表示されます。

int resId = getResources().getIdentifier("action_bar_container", "id", "android");
View actionbarView =  getWindow().getDecorView().findViewById(resId);
于 2015-06-30T11:17:54.990 に答える