码迷,mamicode.com
首页 > 移动开发 > 详细

安卓tablayout控件的使用

时间:2018-01-14 21:26:23      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:sig   void   text   height   nbsp   err   over   ide   layout   

1.加载依赖

    api "com.android.support:design:26.1.0"

2.布局

    <android.support.design.widget.TabLayout
        android:id="@+id/timeline_tablayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

3.初始化和监听

  private void initTab(){
        TabLayout.Tab tab =mTabLayout.newTab();
        tab.setText("默认");
        tab.setTag(0);
        mTabLayout.addTab(tab);

         tab =mTabLayout.newTab();
        tab.setText("价格");
        tab.setTag(1);

        mTabLayout.addTab(tab);

        tab =mTabLayout.newTab();
        tab.setTag(2);
        tab.setText("销量");
        mTabLayout.addTab(tab);
        
        mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                Log.d(TAG, "onTabSelected: "+tab.getTag());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }

4完成

 

安卓tablayout控件的使用

标签:sig   void   text   height   nbsp   err   over   ide   layout   

原文地址:https://www.cnblogs.com/norm/p/8284123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!