【问题标题】:how to edit custom xml from pull to refresh library?如何编辑自定义 xml 从拉到刷新库?
【发布时间】:2014-02-27 13:47:38
【问题描述】:

我必须在我的项目中实现一个PullToRefresh 库。

我需要更改“正在加载...”和“拉动刷新”的文本颜色。所以我阅读了项目里面的文档,我明白它需要在 xml 中完成,但我不确定如何。

我尝试添加“color=0x0”之类的东西,但没有用。

这是要更改的资源文件

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

    <declare-styleable name="PullToRefresh">

        <!-- A drawable to use as the background of the Refreshable View -->
        <attr name="ptrRefreshableViewBackground" format="reference|color" />

        <!-- A drawable to use as the background of the Header and Footer Loading Views -->
        <attr name="ptrHeaderBackground" format="reference|color" />

        <!-- Text Color of the Header and Footer Loading Views -->
        <attr name="ptrHeaderTextColor" format="reference|color" />

        <!-- Text Color of the Header and Footer Loading Views Sub Header -->
        <attr name="ptrHeaderSubTextColor" format="reference|color" />

        <!-- Mode of Pull-to-Refresh that should be used -->
        <attr name="ptrMode">
            <flag name="disabled" value="0x0" />
            <flag name="pullFromStart" value="0x1" />
            <flag name="pullFromEnd" value="0x2" />
            <flag name="both" value="0x3" />
            <flag name="manualOnly" value="0x4" />

            <!-- These last two are depreacted -->
            <flag name="pullDownFromTop" value="0x1" />
            <flag name="pullUpFromBottom" value="0x2" />
        </attr>

        <!-- Whether the Indicator overlay(s) should be used -->
        <attr name="ptrShowIndicator" format="reference|boolean" />

        <!-- Drawable to use as Loading Indicator. Changes both Header and Footer. -->
        <attr name="ptrDrawable" format="reference" />

        <!-- Drawable to use as Loading Indicator in the Header View. Overrides value set in ptrDrawable. -->
        <attr name="ptrDrawableStart" format="reference" />

        <!-- Drawable to use as Loading Indicator in the Footer View. Overrides value set in ptrDrawable. -->
        <attr name="ptrDrawableEnd" format="reference" />

        <!-- Whether Android's built-in Over Scroll should be utilised for Pull-to-Refresh. -->
        <attr name="ptrOverScroll" format="reference|boolean" />

        <!-- Base text color, typeface, size, and style for Header and Footer Loading Views -->
        <attr name="ptrHeaderTextAppearance" format="reference" />

        <!-- Base text color, typeface, size, and style for Header and Footer Loading Views Sub Header -->
        <attr name="ptrSubHeaderTextAppearance" format="reference" />

        <!-- Style of Animation should be used displayed when pulling. -->
        <attr name="ptrAnimationStyle">
            <flag name="rotate" value="0x0" />
            <flag name="flip" value="0x1" />
        </attr>

        <!-- Whether the user can scroll while the View is Refreshing -->
        <attr name="ptrScrollingWhileRefreshingEnabled" format="reference|boolean" />

        <!--
            Whether PullToRefreshListView has it's extras enabled. This allows the user to be 
            able to scroll while refreshing, and behaves better. It acheives this by adding
            Header and/or Footer Views to the ListView.
        -->
        <attr name="ptrListViewExtrasEnabled" format="reference|boolean" />

        <!--
            Whether the Drawable should be continually rotated as you pull. This only
            takes effect when using the 'Rotate' Animation Style.
        -->
        <attr name="ptrRotateDrawableWhilePulling" format="reference|boolean" />

        <!-- BELOW HERE ARE DEPRECEATED. DO NOT USE. -->
        <attr name="ptrAdapterViewBackground" format="reference|color" />
        <attr name="ptrDrawableTop" format="reference" />
        <attr name="ptrDrawableBottom" format="reference" />
    </declare-styleable>

</resources>

我需要文本是黑色的。

这是图书馆的链接(信用):

https://github.com/chrisbanes/Android-PullToRefresh

【问题讨论】:

    标签: android xml colors attr pull-to-refresh


    【解决方案1】:

    当使用PullToRefresh 容器时,您必须在布局文件中定义ptrHeaderTextColor 和/或ptrHeaderSubTextColor

    <com.handmark.pulltorefresh.library.PullToRefreshScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ptr="http://schemas.android.com/apk/res-auto"
    android:id="@+id/pull_refresh_scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none"
    ptr:ptrAnimationStyle="flip"
    ptr:ptrMode="pullFromStart"
    ptr:ptrHeaderTextColor="@android:color/white"
    ptr:ptrHeaderSubTextColor="@android:color/white" >
    
    ...
    
    </com.handmark.pulltorefresh.library.PullToRefreshScrollView>
    

    【讨论】:

    • 谢谢!对于任何不知道的人:所有可能的 PTR 属性都显示在 /res/values/attrs.xml
    【解决方案2】:

    您已将 pull_to_refresh_text textview id 放入您的 res 库文件夹中。让它变黑...

    【讨论】:

      【解决方案3】:

      对布局的所有更改都可以在 res->layout->*.xml 中完成

      在这里您可以找到标签/文本视图并更改颜色。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-17
        • 2021-12-11
        • 1970-01-01
        • 1970-01-01
        • 2011-12-14
        • 1970-01-01
        相关资源
        最近更新 更多