无法找到样式vpiCirclePageIndicatorStyle

时间:2013-12-31 18:18:45

标签: android viewpagerindicator

我想在我的项目中使用viewpageindicator,但导入它时遇到问题。我的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 'vpiCirclePageIndicatorStyle' in current theme

我的XML文件:

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


    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/indicator"
        android:layout_width="248dp"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true"
        android:layout_below="@id/pager"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="30dp"
        android:padding="3dip" />


</RelativeLayout>

我更新了res / values / styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="hololightnoactionbar" parent="android:Theme.Holo.Light">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>

    <style name="dividerstyle" parent="@android:style/Widget.ListView">
        <item name="android:cacheColorHint">@android:color/transparent</item>
        <item name="android:divider">@drawable/list_divider</item>
        <item name="android:dividerHeight">1px</item>
    </style>

    <style name="roundedwhitebox">
        <item name="android:background">@drawable/roundedwhitebox</item>
    </style>

    <style name="roundedlightgraybox">
        <item name="android:background">@drawable/roundedlightgraybox</item>
    </style>

    <style name="rotatingProgressCircle">
        <item name="android:indeterminateDrawable">@drawable/circleindeterminate</item>
    </style>

    <style name="StyledIndicators" parent="@android:style/Theme.Light">
        <item name="vpiCirclePageIndicatorStyle">@style/CustomCirclePageIndicator</item>
        <item name="vpiLinePageIndicatorStyle">@style/CustomLinePageIndicator</item>
        <item name="vpiTitlePageIndicatorStyle">@style/CustomTitlePageIndicator</item>
        <item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item>
        <item name="vpiUnderlinePageIndicatorStyle">@style/CustomUnderlinePageIndicator</item>
    </style>

    <style name="CustomTitlePageIndicator">
        <item name="android:background">#18FF0000</item>
        <item name="footerColor">#FFAA2222</item>
        <item name="footerLineHeight">1dp</item>
        <item name="footerIndicatorHeight">3dp</item>
        <item name="footerIndicatorStyle">underline</item>
        <item name="android:textColor">#AA000000</item>
        <item name="selectedColor">#FF000000</item>
        <item name="selectedBold">true</item>
    </style>

    <style name="CustomLinePageIndicator">
        <item name="strokeWidth">4dp</item>
        <item name="lineWidth">30dp</item>
        <item name="unselectedColor">#FF888888</item>
        <item name="selectedColor">#FF880000</item>
    </style>

    <style name="CustomCirclePageIndicator">
        <item name="fillColor">#FF888888</item>
        <item name="strokeColor">#FF000000</item>
        <item name="strokeWidth">2dp</item>
        <item name="radius">10dp</item>
        <item name="centered">true</item>
    </style>

    <style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator">
        <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>

    <style name="CustomUnderlinePageIndicator">
        <item name="selectedColor">#FFCC0000</item>
        <item name="android:background">#FFCCCCCC</item>
        <item name="fadeLength">1000</item>
        <item name="fadeDelay">1000</item>
    </style>

</resources>

我的项目结构在这里,其中vpilibrary是导入的viewpageindicator库

enter image description here

它出了什么问题?如果您需要更多文件进行调试,请告诉我。 THX

ps:我的minsdkversion和targetsdkversion都是16

4 个答案:

答案 0 :(得分:16)

<强>问题: Problem

<强>解决方案:

  1. res/layout/values/styles.xml
  2. 中添加自定义样式

    您可以找到一些示例here

    <style name="StyledIndicators" parent="@android:style/Theme.Light">
        <item name="vpiCirclePageIndicatorStyle">@style/CustomCirclePageIndicator</item>
    </style>
    
    <style name="CustomCirclePageIndicator">
        <item name="fillColor">#000000</item>
        <item name="strokeColor">#000000</item>
        <item name="strokeWidth">1dp</item>
        <item name="radius">6dp</item>
        <item name="centered">true</item>
    </style>
    
    1. 在您的活动中添加新样式作为主题,&#34; StyledIndicators&#34;:

      <activity
          android:name=".YourActivity"
          android:theme="@style/StyledIndicators" >
      </activity>
      
    2. 之后只需要将主题更改为项目附带的主题,选择Manifest Themes - StyledIndicators。

    3. enter image description here

答案 1 :(得分:9)

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Light.NoTitleBar">
    <item name="vpiCirclePageIndicatorStyle">@style/CustomCirclePageIndicator</item>
</style>
<style name="CustomCirclePageIndicator">
    <item name="fillColor">#FF888888</item>
    <item name="strokeColor">#FF000000</item>
    <item name="strokeWidth">2dp</item>
    <item name="radius">10dp</item>
    <item name="centered">true</item>
</style>
</resources>

现在在您的清单文件中。 在

下添加主题属性
<application
    android:icon="@drawable/icon"
    android:label="ViewPagerIndicator Sample"
    android:theme="@style/AppTheme" >

别忘了添加

  android:theme="@style/AppTheme"

答案 2 :(得分:6)

使用ViewPagerIndicator的活动需要在其主题中具有适当的样式。

this sample project中,我演示了使用必备vpiTabPageIndicatorStyle设置自定义主题:

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

        <style name="AppTheme" parent="@style/Theme.Sherlock.Light">
                <item name="vpiTabPageIndicatorStyle">@style/TabStyle</item>
        </style>

        <style name="TabStyle" parent="Widget.TabPageIndicator">
                <item name="android:textColor">#FF33AA33</item>
                <item name="android:textSize">14sp</item>
                <item name="android:textStyle">italic</item>
                <item name="android:paddingLeft">16dp</item>
                <item name="android:paddingRight">16dp</item>
                <item name="android:fadingEdge">horizontal</item>
                <item name="android:fadingEdgeLength">8dp</item>
        </style>

</resources>

同样的基本方法应该适用于vpiCirclePageIndicatorStyle,我认为ViewPagerIndicator附带的示例代码就是一个例子。

答案 3 :(得分:0)

要将自定义样式应用于圆形页面指示符,请在xml布局中直接添加样式属性。

double d = 1000000000;
DecimalFormat df = new DecimalFormat("#");
System.out.println(df.format(d));