gpt4 book ai didi

android - PagerTabStrip 未显示

转载 作者:行者123 更新时间:2023-11-29 15:42:23 28 4
gpt4 key购买 nike

我正在制作滑动标签 View 。我想在 SupportActionBar 的底部显示 PagerTabStrip。所有选项卡的内容都显示良好,但问题是这些选项卡的标题未显示,而且 PagerTabStrip 未显示在 SupportActionBar 的底部。

main_tab.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal">


<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >

<android.support.v4.view.PagerTabStrip
android:layout_width="wrap_content"
android:layout_height="100dp"
android:background="#e62117"
android:id="@+id/tab_strip"
android:focusableInTouchMode="false">
</android.support.v4.view.PagerTabStrip>

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

tab1、tab2、tab3:类似

  public class tab1 extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab1,container,false);
return view;
}
}

ma_page_adapter:

public class ma_pager_adapter extends FragmentPagerAdapter {
public ma_pager_adapter(FragmentManager fm) {
super(fm);
}


@Override
public Fragment getItem(int i) {

switch (i) {
case 0:
tab1 t1 = new tab1();
return t1;
case 1:
tab2 t2 = new tab2();
return t2;
case 2:
tab3 t3 = new tab3();
return t3;

}
return null;
}

@Override
public int getCount() {
return 3;
}//set the number of tabs

@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return "Top stories";
case 1:

return "Members";
case 2:

return "Setting";
}
return null;
}
}

主要 Activity :

   ViewPager pager;
PagerTabStrip tab_strp;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_tab);
ma_pager_adapter mapager = new ma_pager_adapter(getSupportFragmentManager());


pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(mapager);
// tab_strp = (PagerTabStrip) findViewById(R.id.tab_strip);
((ViewPager.LayoutParams) findViewById(R.id.tab_strip).getLayoutParams()).isDecor = true;
// tab_strp.setTextColor(Color.WHITE);
}
}

最佳答案

您的问题与以下问题重复:

PagerTabStrip not showing in ViewPager in app targeting Android 6.X (N)

对于面向 Android N 的应用,您需要使用以下解决方法:

在 onCreateView() 中,添加以下内容:

((ViewPager.LayoutParams) (view.findViewById(R.id.tab_strip)).getLayoutParams()).isDecor = true;

关于android - PagerTabStrip 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38373647/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com