简体   繁体   English

在标准23或22上,标题根本不出现在PagerTitleStrip中

[英]The Titles do not appear in PagerTitleStrip at all on sdk 23 or 22

i have tried several things to display the text in the tabs on "scroll tabs" in my activity but it never shows 我已经尝试了几个东西来显示我的活动中“滚动标签”选项卡中的文本,但它从未显示

any ideas what happened? 发生了什么事?

below is the code: 以下是代码:

scrollabletabs.xml: scrollabletabs.xml:

<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/pager">
<android.support.v4.view.PagerTitleStrip
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:paddingTop="20dp"
    android:paddingBottom="20dp"
    android:layout_gravity="top"
    android:background="@color/material_deep_teal_500"
    android:id="@+id/tabtitle"
    style="@style/pagertitlestrip">

</android.support.v4.view.PagerTitleStrip>

</android.support.v4.view.ViewPager>

ScrolllableTabs.java: ScrolllableTabs.java:

package com.example.pc.learn_again;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

public class ScrollableTabs extends FragmentActivity {

//get the ViewPager//
ViewPager viewPager=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.scrollabletabs);
    viewPager = (ViewPager) findViewById(R.id.pager);
    //the connection between the ViewPager and the adapter is below//
    FragmentManager fragmentManager = getSupportFragmentManager();
    viewPager.setAdapter(new myadapter(fragmentManager));
}
}

class myadapter extends FragmentPagerAdapter
{

public myadapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int position) {
    //as you see from the below this is how we tell the Viewpager which fragment (page) to be shown//
    Fragment fragment=null;
    if (position==0)
    {
        fragment = new ScrollableFragment1();
    }
    if (position==1)
    {
        fragment = new ScrollableFragment2();
    }
    if (position==2)
    {
        fragment = new ScrollableFragment3();
    }
    return fragment;
}

@Override
public int getCount() {

    return 3;//this is the number of pages
}
//the below is for the titles//

@Override
public CharSequence getPageTitle(int position) {

    if (position==0)
    {
        return "Login Screen";
    }
    if (position==1)
    {
        return " List View";
    }
    if (position==2)
    {
        return "Calculator";
    }
    return null;
}
}

let me point out that the fragments appear correctly and they work fine , but i do not know why the titles in the tabs do not show (is it possible that the method returns null?? and if yes....why??) 让我指出片段出现正确,它们工作正常,但我不知道为什么标签中的标题不显示(该方法可能返回null ??如果是的话......为什么??)

thx for the help guys :) thx的帮助人:)

Use: 采用:

<android.support.v4.view.PagerTabStrip

        android:id="@+id/strip"

        android:layout_gravity="top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="4dp"
        android:textColor="#fff"

        android:background="@android:color/holo_blue_bright"></android.support.v4.view.PagerTabStrip>

instead of 代替

<android.support.v4.view.PagerTitleStrip
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:paddingTop="20dp"
    android:paddingBottom="20dp"
    android:layout_gravity="top"
    android:background="@color/material_deep_teal_500"
    android:id="@+id/tabtitle"
    style="@style/pagertitlestrip">

The PageTabStrip worked for me. PageTabStrip为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM