Search code examples
androidtextandroid-actionbarpull-to-refresh

Change Text for loading screen in ActionBar-PullToRefresh library


I have successfully implemented ActionBar-PullToRefresh in my code. Now whenever I refresh the list it shows "Loading ..." text in ActionBar.

So how to change that text in ActionBar. Do I directly change the string in the library or is there any other way to do that...


Solution

  • Approved approach from the samples

    Source: https://github.com/chrisbanes/ActionBar-PullToRefresh/tree/master/samples

    1. Create a theme with text overrides (e.g. ptrPullText),
      that is, res/values/styles.xml:

      <resources>
          <style name="Theme.Holo.CustomPtrHeader" parent="android:Theme.Holo">
              <item name="ptrHeaderStyle">@style/Widget.Custom.PtrHeader</item>
          </style>
          <style name="Widget.Custom.PtrHeader" parent="android:Widget">
              <item name="ptrRefreshingText">Pulling down the internet</item>
          </style>
      </resources>
      
    2. Apply the custom theme to your activity in AndroidManifest.xml

      <activity
          ...
          android:theme="@style/Theme.Holo.CustomPtrHeader" />
      

    or Register you own HeaderTransformer

    For the example on how to do this, please see the GridView sample.

    or A little hackier way

    Please note that setPullText is not on the HeaderTransformer interface, it's an instance method of DefaultHeaderTransformer:

    attacher = PullToRefreshAttacher.get(this);
    attacher.addRefreshableView(listView, this);
    transformer = ((DefaultHeaderTransformer)attacher.getHeaderTransformer());
    transformer.setRefreshingText("Pulling down the internet");