【问题标题】:SlidingTabLayout not displaying the titleSlidingTabLayout 不显示标题
【发布时间】:2015-11-01 21:26:36
【问题描述】:

我使用本教程进行滑动:http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html 并且滑动类来自谷歌回购

主要活动

ViewPager pager;
    ViewPagerAdapter adapter;
    SlidingTabLayout tabs;
    CharSequence Titles[]={"Home","Events"};
    int Numboftabs =2;     

class...
adapter =  new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);

        // Assigning ViewPager View and setting the adapter
        pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(adapter);

        // Assiging the Sliding Tab Layout View
        tabs = (SlidingTabLayout) findViewById(R.id.tabs);
        tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

        // Setting Custom Color for the Scroll bar indicator of the Tab View
        tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
            @Override
            public int getIndicatorColor(int position) {
                return getResources().getColor(R.color.tabsScrollColor);
            }
        });

        // Setting the ViewPager For the SlidingTabsLayout
        tabs.setViewPager(pager);

适配器:

package com.leifacil.vademecum.Activities;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

/**
 * Created by hp1 on 21-01-2015.
 */
public class ViewPagerAdapter extends FragmentStatePagerAdapter {

    CharSequence Titles[]; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created
    int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created


    // Build a Constructor and assign the passed Values to appropriate values in the class
    public ViewPagerAdapter(FragmentManager fm,CharSequence mTitles[], int mNumbOfTabsumb) {
        super(fm);

        this.Titles = mTitles;
        this.NumbOfTabs = mNumbOfTabsumb;

    }

    //This method return the fragment for the every position in the View Pager
    @Override
    public Fragment getItem(int position) {

        if(position == 0) // if the position is 0 we are returning the First tab
        {
            Tab1 tab1 = new Tab1();
            return tab1;
        }
        else             // As we are having 2 tabs if the position is now 0 it must be 1 so we are returning second tab
        {
            Tab2 tab2 = new Tab2();
            return tab2;
        }


    }

    // This method return the titles for the Tabs in the Tab Strip

    @Override
    public CharSequence getPageTitle(int position) {

        return Titles[position];
    }

    // This method return the Number of tabs for the tabs Strip

    @Override
    public int getCount() {
        return NumbOfTabs;
    }
}

我不知道为什么,但它没有显示标题=/

我不能发布图片,所以就这样吧:

http://i.stack.imgur.com/A2ct8.png

链接两个我不能放图片-_-,但是第二个图片是/Jnihu.png

编辑 .xml:

 <com.mypackage.Tools.SlidingTabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@android:color/holo_green_dark"
    android:layout_below="@+id/toolbar_top"
        android:layout_alignParentLeft="true" />
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"

        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/tabs"></android.support.v4.view.ViewPager>

【问题讨论】:

  • 你也可以发布xml吗?
  • ofc =),添加 1 分钟
  • @Senhor Obvio 上面代码中的 populateTabStrip() 方法在哪里?你应用了 TabTitleView 的 TextColor() 吗?
  • @DhruvVaishnav 我试过这个tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { @Override public int getIndicatorColor(int position) { return getResources().getColor(R.color.tabsScrollColor); } });
  • 和 tabsScrollColor -> ``` #ffffff ```

标签: android pagerslidingtabstrip


【解决方案1】:

试试

android:elevation="2dp" 

在您的 ToolBarSlidingTabLayout

但是

Pre-Lollipop 不允许这个属性,所以你可以使用阴影 :( 但这有点棘手

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-02
    • 2020-12-08
    • 2011-01-03
    • 2010-12-28
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多