Im developing an app for school purposes. Is it possible to create a swipeable tabs with toolbar instead of using an actionbar? Coz i've change my style theme into NoActionbar and i dont know now how to add tablayout :( Thanks in advance :)
Asked
Active
Viewed 176 times
1
-
https://github.com/neokree/MaterialTabs – Androider Nov 08 '15 at 14:55
-
Hello there @Androider. Thanks for the response. I have red from the link that you've given me that "I have not enough time to continue developing at this time and the android design support library implements the tabs features in the better way, so I think it is useless now." Is there any other way ? thanks :) – bluelover Nov 08 '15 at 15:09
-
http://stackoverflow.com/questions/31698756/remove-line-break-in-tablayout/32547335#32547335 – Daniel Nugent Nov 08 '15 at 15:30
-
For tabs on the bottom: http://stackoverflow.com/questions/32984706/how-can-i-set-tabs-at-the-bottom-and-also-hide-top-actionbar/32985326#32985326 – Daniel Nugent Nov 08 '15 at 15:35
-
Thanks @Daniel Nugent. this is a good help :) – bluelover Nov 08 '15 at 15:50
1 Answers
0
Try embed the TabLayout in the ToolBar like
<android.support.v7.widget.Toolbar android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
android:background="?attr/colorPrimary">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</android.support.v7.widget.Toolbar>
And then setup every thing in java code as
Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar=getSupportActionBar();
actionBar.setTitle(null);
String[] tabs={
"Tab_1","Tab_2","Tab_3"
};
TabLayout tabLayout=(TabLayout) findViewById(R.id.tabLayout);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
for(String name:tabs){
tabLayout.addTab(tabLayout.newTab().setText(name));
}
Hope this is helpful

Collins Abitekaniza
- 4,496
- 2
- 28
- 43