Tab ниже action bar

Рейтинг: 1Ответов: 1Опубликовано: 20.12.2014

пытаюсь добавить tabs, он либо выходит, но поверх action bar, либо вообще не выходит, если я перемещаю таб ниже:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v4.widget.DrawerLayout

    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.Toolbar
            android:id="@+id/my_awesome_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            android:background="?attr/colorAccent"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
             />

        <TabHost
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/tabHost"
            android:layout_gravity="center_horizontal|top">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical">

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="29dp"></TabWidget>

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <LinearLayout
                        android:id="@+id/tab1"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:orientation="vertical">
                        <fragment
                            android:name="com.example.eldos.callreport.Fragment1"
                            android:id="@+id/frag1"
                            android:layout_height="wrap_content"
                            android:layout_width="match_parent"
                            tools:layout="@layout/fragment1"/>
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/tab2"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:orientation="vertical"></LinearLayout>

                </FrameLayout>
            </LinearLayout>
        </TabHost>

    </FrameLayout>

    <ListView
        android:id="@+id/lv_navigation_drawer"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white" />

</android.support.v4.widget.DrawerLayout>

</LinearLayout>

Как я могу его поместить ниже?

Пытаюсь сделать sliding tab, скачал сэмпл, но там совсем непонятно, или это старый сэмпл. Сделал, как там, все точно так же, но табы даже не появились, они там применяют, скорее всего, старый метод. Может быть, есть уже готовый способ?

Ответы

▲ 2Принят

Судя по комменту к ответу этого вопроса, вы получаете null при вызове

getSupportActionBar();

Моё предположение - у вас Toolbar не назначен ActionBar-ом. Делается это так:

в onCreate() активити находим Toolbar и...

 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
 setSupportActionBar(toolbar);

После этого должны работать все фишки с табами, т.к. getSupportActionBar(); больше не будет возвращать null.