I have been studying Android for two weeks. Now I am developing my first Android project.
In my project I need to work with Tabs together with action bar. I know that is very common in Android. For action bar I am using toolbar with v7. I seriously know about action bar. But I have an issue with tab layout. The problem is I want to add tabs to tab layout in layout XML file.
For example:
<TabLayout>
//tab buttton goes here
 <TabButton1></TabButton1>
 <TabButton1></TabButton1>
 .
 .
<TabLayout>
I search so many tutorials about tablayout. But all tutorials define tabs for tab layout programmatically. How can I define tabs for tab layout in XML and define event for them programmatically by findViewById? I don't want to use button view instead of tabs.
This should be what you want:
<android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="bottom"
            android:background="?attr/colorPrimary"
            app:tabMode="fixed">
            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Popular" />
            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Most Rated" />
            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Favorites" />
        </android.support.design.widget.TabLayout>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With