默认样式失败ViewPagerIndicator的TabPageIndicator。为什么以及如何解决? [英] Default Style Fails for ViewPagerIndicator's TabPageIndicator. Why and How to Fix?

查看:407
本文介绍了默认样式失败ViewPagerIndicator的TabPageIndicator。为什么以及如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而不是解释的问题,如果我只是告诉你要容易得多:

Instead of explaining the issue, much easier if I just show you:

正如你所看到的选项卡标题都一起捣碎和完全无样式。他们正常在刷卡通过切换标签(虽然有不同的位置没有明显的指示转向适当的地方),按一个选项卡切换视图,但所有的风格缺失。这里是code:

As you can see the tab titles are all mashed together and entirely unstyled. They function correctly in that swiping through switches tabs (though there's no visible indication except position shifting where appropriate) and tapping a tab switches the view, but all style is missing. Here is the code:

gallerylists.xml

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

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)
  }
}

就是这样。现在,除非我不顾阅读文档并检查样品很迷茫,我不应该采取任何额外的步骤,使用默认的样式。我在一个小的损失的。

That's it. Now, unless I'm very confused despite reading the documentation and examining the samples, I shouldn't have to take any extra steps to use the default style. I'm at a bit of a loss.

推荐答案

我觉得自己像一个有点白痴,但这里是非常简单明了的解决方案。

I feel like a bit of a moron, but here is the exceedingly simple and obvious solution.

AndroidManifest.xml中

AndroidManifest.xml

...
<activity
  android:name=".GalleryLists"
  android:theme="@style/Theme.PageIndicatorDefaults"
  ... >
</activity>
...

是的,所有我需要做的是真正的使用的主题。希望这将有助于其他一些迷途的灵魂。

Yeah, all I needed to do was actually use the theme. Hopefully this will help some other poor lost soul.

这篇关于默认样式失败ViewPagerIndicator的TabPageIndicator。为什么以及如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆