无法在Android项目中使用viewpager选项卡

时间:2015-01-02 12:19:45

标签: android android-viewpager

我在做什么:我正在尝试使用视图寻呼机标签指示器。

我做了什么:

  • 我已将图书馆链接
  • 我已在所有值文件夹
  • 中反映了styles.xml
  • 从样本
  • 复制所有必需的drawables

清单:

<activity
    android:name="com.windhyaworks.activities.ActMain"
    android:configChanges="orientation|keyboardHidden"
    android:screenOrientation="portrait"
    android:theme="@style/StyledIndicators" />

styles.xml

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <style name="mydialogstyle" parent="android:style/Theme.Dialog">
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:windowNoTitle">false</item>
    </style>

    <style name="StyledIndicators" parent="AppTheme">
        <item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item>
    </style>

    <style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator">
        <item name="android:background">@drawable/custom_tab_indicator</item>
        <item name="android:textAppearance">@style/CustomTabPageIndicator.Text</item>
        <item name="android:textColor">#FF555555</item>
        <item name="android:textSize">16sp</item>
        <item name="android:divider">@drawable/custom_tab_indicator_divider</item>
        <item name="android:dividerPadding">10dp</item>
        <item name="android:showDividers">middle</item>
        <item name="android:paddingLeft">8dp</item>
        <item name="android:paddingRight">8dp</item>
        <item name="android:fadingEdge">horizontal</item>
        <item name="android:fadingEdgeLength">8dp</item>
    </style>

    <style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
        <item name="android:typeface">monospace</item>
    </style>

</resources>

在XML图形中我看不到布局,我在下面看到这些警告。

Missing styles. Is the correct theme chosen for this layout?
Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.

Failed to find style 'vpiTabPageIndicatorStyle' in current theme
Exception raised during rendering: ViewPager has not been bound.
Exception details are logged in Window > Show View > Error Log

java.lang.IllegalStateException: ViewPager has not been bound.
    at com.viewpagerindicator.TabPageIndicator.setCurrentItem(TabPageIndicator.java:240)
    at com.viewpagerindicator.TabPageIndicator.onMeasure(TabPageIndicator.java:116)
    at android.view.View.measure(View.java:17430)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
    at android.view.View.measure(View.java:17430)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
    at android.view.View.measure(View.java:17430)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
    at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:447)
    at android.view.View.measure(View.java:17430)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1083)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:615)
    at android.view.View.measure(View.java:17430)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
    at android.view.View.measure(View.java:17430)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:875)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
    at android.view.View.measure(View.java:17430)

1 个答案:

答案 0 :(得分:0)

idk是Eclipse或AndroidStudio或其他东西。

我在Android Studio工作,有时候我没有获得自动填充选项(对于支持库)。 相反,我做:

  • 删除该布局文件
  • 制作一个新的(如果您已经在代码中使用了相同的名称),并在根元素类型下使用ViewPager
  • 它应该启动ViewPager代码,如果没有,在 Design 选项卡中它将报告问题(类似于你提到的那些)并链接到v4-ViewPager。点击它,你应该有起始代码。