android-tablayout

How to get current selected tab index in TabLayout?

喜你入骨 提交于 2019-12-09 07:36:08
问题 When I use ActionBar tabs, I use this code. private int getCurrentTabIndex() { ActionBar actionBar = activity.getSupportActionBar(); ActionBar.Tab selectedTab = actionBar.getSelectedTab(); if(selectedTab == null){ return 0; } return selectedTab.getPosition(); } But how can I do it using TabLayout? 回答1: Use OnTabSelectedListener. And then in this listener get the getPosition(). Something like this: tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){ @Override public void

Android Tab Layout not taking up full width with custom view

喜你入骨 提交于 2019-12-09 05:52:48
问题 Android TabLayout tabPaddingTop and tabPaddingBottom not being removed Please refer to the above issue as well. Even since i updated my design library to "23.2.0", Tab layout is all messed up. The below image is my Tab Layout. Xml Part :- <android.support.design.widget.TabLayout android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabIndicatorColor="@android:color/white" app:tabIndicatorHeight="@dimen/dp2" app:tabMode="fixed" app

How do I get the view of a Tab in a TabLayout?

大憨熊 提交于 2019-12-09 05:47:51
问题 I'd like to find the view of a Tab in a TabLayout so that I can pass it to another function. I'm not sure how to go about finding the view. myTabLayout.getTabAt(0).getCustomView() returns null. How do I get the view? TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tab_layout_main); tabLayout.addTab(tabLayout.newTab().setText("Page1")); tabLayout.addTab(tabLayout.newTab().setText("Page2")); viewPager = (ViewPager) rootView.findViewById(R.id.pager_main); pagerAdapter = new

How is TabItem used when placed in the layout XML?

自古美人都是妖i 提交于 2019-12-08 23:10:52
问题 The TabLayout documentation gives an example of nesting TabItem directly inside TabLayout like so: <android.support.design.widget.TabLayout android:layout_height="wrap_content" android:layout_width="match_parent"> <android.support.design.widget.TabItem android:text="@string/tab_text"/> <android.support.design.widget.TabItem android:icon="@drawable/ic_android"/> </android.support.design.widget.TabLayout> But it gives no example of how this could be used in practice, and the documentation for

Disable Tabs in TabLayout

独自空忆成欢 提交于 2019-12-08 18:37:46
问题 I have used TabLayout from the latest design support library in my app. The tabs are attached to a viewpager which loads the fragments for each tab. I want to disable all the tabs until the viewpager loads the fragment for user selected tab. I am not able to disable the tablayout or make it non-clickable. I had used setEnabled(false) and setClickable(false) but it is not working. I am able to make it invisible by using setVisiblity(View.GONE) but I want the tabs to be visible at all times.

How to set Custom tab in tab layout in android

≡放荡痞女 提交于 2019-12-08 11:33:30
问题 actvity_main.xml <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.TabLayout android:id="@+id/tabs"

setupWithViewPager is not exist in tabLayout

不羁岁月 提交于 2019-12-08 05:57:04
问题 public class ActivityManageCustomer extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_manage_customer); ViewPager viewpager = (ViewPager) findViewById(R.id.viewpager); viewpager.setAdapter(new AdapterFragmentCustomer(getSupportFragmentManager())); TableLayout tabLayout = (TableLayout) findViewById(R.id.tabLayout); tabLayout.setupWithViewPager(viewpager); } } setupWithViewPager is not

How can I set the height of tabs in Android a TabLayout?

跟風遠走 提交于 2019-12-07 06:27:03
问题 I Have this TabLayout in Android and wanted to make the tabs a little heigher than the default (48dp) <android.support.design.widget.TabLayout android:id="@+id/contentTabs" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Theme.Zhaw.TabLayout" app:tabMode="fixed" app:tabGravity="fill"/> Here is the Style Theme.Zhaw.TabLayout: <style name="Theme.Zhaw.TabLayout" parent="Widget.Design.TabLayout"> <item name="tabIndicatorColor">@color/text_white</item> <item

click on tab layout doesn't work at all

房东的猫 提交于 2019-12-07 05:23:24
问题 I have implemented this example. but not able to click on 2nd tab. my xml file looks like <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/header" android:orientation="horizontal"> <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="fill_parent" android:layout_height="48dp" android:layout_below="@+id/header" android:background="@color/colorPrimary" app:tabSelectedTextColor="#ffffff" />