问题描述
我试图实现与SherlockActionBar的ViewPagerIndicator。它的工作原理:我可以滑动的片段,但款式不能正常工作
I'm trying to implement the ViewPagerIndicator with SherlockActionBar. It works: I can slide the fragments, but the style doesn't work!
它看起来像这样: http://imgur.com/wMlCC (相关主题:https://github.com/JakeWharton/Android-ViewPagerIndicator/issues/66)
It looks like this: http://imgur.com/wMlCC (related topic: https://github.com/JakeWharton/Android-ViewPagerIndicator/issues/66)
我知道发生了什么错误:在VPI的样品,一个页面的样式是通过设置在AndroidManifest.xml中(例如)
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>
但是,当我再补充一点安卓主题元素,以我自己的Manifest.xml我得到以下异常:
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.
我也试着给所有的样式信息复制到styles.xml,但也不能正常工作。
I've also tried to copy all the style-information to styles.xml, but that also doesn't work.
你能告诉我如何设置一个样式的VPI?谢谢!
Can you tell me how to set a style to the VPI?Thank you!
编辑:现在,我已经添加了
Now I've added
<activity
android:name=".SampleTabsDefault"
android:theme="@style/StyledIndicators">
</activity>
我的Manifest.xml
to my Manifest.xml
和下面的风格在styles.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 :(
该活动的code可以在这里找到: http://pastebin.com/hsNgxFDZ 当前页面的风格截图: http://imgur.com/GrTPA
The code of the activity can be found here: http://pastebin.com/hsNgxFDZScreenshot of current page with style: http://imgur.com/GrTPA
推荐答案
为了看片段,你必须以某种方式延长一个Android基本主题。为了看ViewPagerIndicator,你必须以某种方式包括那些样式定义。答案是创建自己的主题,它扩展了ActionBarSherlock主题(它扩展了Android的基本主题),并实现了ViewPagerIndicator-风格。
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.
例如:
<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>
然后在你的清单,设定安卓主题=@风格/ mytheme的
到&lt;应用&GT;
或你的&LT;活性GT;
取值
请注意,您不必包括所有4VPI ...... - 风格;你只需要包括那些使用。例如。如果你只使用CirclePageIndicator,你只需要包括&LT;项目名称=vpiCirclePageIndicatorStyle&GT; ...&LT; /项目&GT;
键,可以省略其他3项声明。
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组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!