gpt4 book ai didi

android - ViewPagerIndicator 的 TabPageIndicator 的默认样式失败。为什么以及如何解决?

转载 作者:IT老高 更新时间:2023-10-28 23:28:42 25 4
gpt4 key购买 nike

如果我只是向您展示,而不是解释问题,会容易得多:

Unstyled Tab Titles

如您所见,选项卡标题全部混合在一起并且完全没有样式。它们在通过切换选项卡滑动时正常工作(尽管除了在适当的位置移动之外没有可见的指示)并点击选项卡切换 View ,但所有样式都丢失了。代码如下:

gallerylists.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<com.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

<android.support.v4.view.ViewPager
android:id="@+id/gallerypager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

</LinearLayout>

GalleryLists.java

public class GalleryLists extends Activity {
Context context;

private static final String[] titles = new String[] {
"20 Hottest", "20 Worst", "20 Awesomest", "MMA", "Comedy", "Moto", "Games" };

ViewPager listPager;
ListPagerAdapter listPagerAdapter;

PageIndicator indicator;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallerylists);

context = this;

listPagerAdapter = new ListPagerAdapter();

ViewPager.OnPageChangeListener changeListener = new ViewPager.OnPageChangeListener() {

@Override
public void onPageScrolled(int i, float v, int i1) {}

@Override
public void onPageSelected(int i) {}

@Override
public void onPageScrollStateChanged(int i) {}
};

listPager = (ViewPager) findViewById(R.id.gallerypager);
listPager.setAdapter(listPagerAdapter);
listPager.setOnPageChangeListener(changeListener);

indicator = (TabPageIndicator) findViewById(R.id.indicator);
indicator.setViewPager(listPager);
indicator.setOnPageChangeListener(changeListener);
}

private class ListPagerAdapter extends PagerAdapter {

// Not important (I believe)
}
}

就是这样。现在,除非我在阅读文档和检查示例时感到非常困惑,否则我不应该采取任何额外的步骤来使用默认样式。我有点不知所措。

最佳答案

我有同样的问题,但 android:theme="@style/Theme.PageIndicatorDefaults" 没有与我的应用主题结合。

还有另一种个性化的方式,覆盖res/values/style.xml:

<resources>

<style name="AppTheme" parent="android:Theme.Light" >
<item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item>

</style>

<style name="CustomTabPageIndicator" >
<item name="android:gravity">center</item>
<item name="android:background">@drawable/vpi__tab_indicator</item>
<item name="android:paddingTop">12dp</item>
<item name="android:paddingBottom">12dp</item>
<item name="android:textAppearance">@style/TextAppearance.TabPageIndicator</item>
<item name="android:textSize">15sp</item>
<item name="android:maxLines">1</item>
<item name="android:textColor">#FF555555</item>
</style>
</resources>

关于android - ViewPagerIndicator 的 TabPageIndicator 的默认样式失败。为什么以及如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11873396/

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