无样式 ViewPagerIndicator 与 SherlockActionBar 结合使用

No style ViewPagerIndicator in combination with SherlockActionBar(无样式 ViewPagerIndicator 与 SherlockActionBar 结合使用)

本文介绍了无样式 ViewPagerIndicator 与 SherlockActionBar 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SherlockActionBar 实现 ViewPagerIndicator.有效:我可以滑动片段,但样式不起作用!

看起来像这样:

相关话题:

解决方案

为了查看 Fragments,您必须以某种方式扩展 Android 基础主题.为了查看 ViewPagerIndicator,您必须以某种方式包含这些样式定义.答案是创建自己的主题,扩展 ActionBarSherlock 主题(扩展 Android 基础主题),并实现 ViewPagerIndicator 样式.

例子:

<style name="myTheme" parent="@style/Theme.Sherlock"><!-- 如果要使用默认的 ViewPagerIndicator 样式,请使用以下内容:--><item name="vpiTitlePageIndicatorStyle">@style/Widget.TitlePageIndicator</item><item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item><item name="vpiTabTextStyle">@style/Widget.TabPageIndicator.Text</item><!-- 如果你想实现你自定义的 CirclePageIndicator 样式,可以这样:--><item name="vpiCirclePageIndicatorStyle">@style/myCirclePageIndicator</item><!-- 将您想要定义的任何其他样式放入自定义主题中 --></风格><style name="myCirclePageIndicator" parent="Widget.CirclePageIndicator"><item name="fillColor">@color/my_custom_circle_indicator_fill_color</item></风格>

然后在您的 Manifest 中,将 android:theme="@style/myTheme" 设置为 <application> 或您的 <activity>s.

请注意,您不必包含所有 4 个vpi..."样式;你只需要包括你使用的那些.例如.如果您只使用 CirclePageIndicator,您只需包含 <item name="vpiCirclePageIndicatorStyle">...</item> 并且可以省略其他 3 个项目声明.

I'm trying to implement the ViewPagerIndicator with SherlockActionBar. It works: I can slide the fragments, but the style doesn't work!

It looks like this:

related topic: https://github.com/JakeWharton/Android-ViewPagerIndicator/issues/66

I know what's going wrong: In the sample of VPI, the style of a page is set in AndroidManifest.xml by (for example)

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

But when I add that android:theme element to my own Manifest.xml I get the following exception:

03-16 11:06:24.400: E/AndroidRuntime(483): Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.

I've also tried to copy all the style-information to styles.xml, but that also doesn't work.

Can you tell me how to set a style to the VPI? Thank you!

EDIT: Now I've added

<activity
         android:name=".SampleTabsDefault"
         android:theme="@style/StyledIndicators"> 
</activity>

to my Manifest.xml

and the following style in styles.xml

<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
        <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
    </style>   

    <style name="StyledIndicators" parent="Theme.BataApp">
        <item name="vpiTitlePageIndicatorStyle">@style/Widget.TitlePageIndicator</item>
        <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
        <item name="vpiTabTextStyle">@style/Widget.TabPageIndicator.Text</item>
    </style>

Result: I don't get any Exception, see the style, but I now I can't see any fragments :(

The code of the activity can be found here: http://pastebin.com/hsNgxFDZ Screenshot of current page with style:

解决方案

In order to see the Fragments, you'll have to somehow extend an Android base-theme. In order to see the ViewPagerIndicator, you'll have to somehow include those style-definitions. The answer is to create your own theme that extends the ActionBarSherlock-theme (which extends the Android base-themes), and implements the ViewPagerIndicator-styles.

Example:

<style name="myTheme" parent="@style/Theme.Sherlock">

    <!-- If you want to use the default ViewPagerIndicator-styles, use the following: -->
    <item name="vpiTitlePageIndicatorStyle">@style/Widget.TitlePageIndicator</item>
    <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
    <item name="vpiTabTextStyle">@style/Widget.TabPageIndicator.Text</item>

    <!-- If you want to implement your custom style of CirclePageIndicator, do it like so: -->
    <item name="vpiCirclePageIndicatorStyle">@style/myCirclePageIndicator</item>


    <!-- Put whatever other styles you want to define in your custom theme -->
</style>

<style name="myCirclePageIndicator" parent="Widget.CirclePageIndicator">
    <item name="fillColor">@color/my_custom_circle_indicator_fill_color</item>
</style>

Then in your Manifest, set android:theme="@style/myTheme" to the <application> or to your <activity>s.

Note that you don't have to include all 4 "vpi..."-styles; you only have to include those that you use. E.g. if you're only using the CirclePageIndicator, you only have to include <item name="vpiCirclePageIndicatorStyle">...</item> and can leave out the other 3 item declarations.

这篇关于无样式 ViewPagerIndicator 与 SherlockActionBar 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:无样式 ViewPagerIndicator 与 SherlockActionBar 结合使用

基础教程推荐