Is there a way to modify the color of the arrow in a SwipeRefreshLayout using theme ?
I know that you can use this code programaticaly
public void setColorSchemeResources (int... colorResIds)
But I'd like to have the arrow set to the theme of my app by default, and not having to change it in the code each time I use a SwipeRefrestLayout somewhere.
Add the SwipeRefreshLayout Widget To add the swipe to refresh widget to an existing app, add SwipeRefreshLayout as the parent of a single ListView or GridView . Remember that SwipeRefreshLayout only supports a single ListView or GridView child. You can also use the SwipeRefreshLayout widget with a ListFragment .
Android SwipeRefreshLayout is a ViewGroup that can hold only one scrollable child. It can be either a ScrollView, ListView or RecyclerView.
To disable the gesture and progress animation, call setEnabled(false) on the view. This layout should be made the parent of the view that will be refreshed as a result of the gesture and can only support one direct child.
Activity Code for Pull to Refresh Functionality in KotlininiRefreshListener() method will set a listener to the SwipeRefreshLayout and pull to refresh operation is performed by the user. In the above code, we are calling the function iniRefreshListener() and to load Xml we have to call the setContentView(R. layout.
As of support v4 23.0.1 the only attribute pulled from xml in the SwipeRefreshLayout constructor is android.R.attr.enabled
Meaning no, the only way to set the colors, is in code.
However you could create an array resource of the color id's to hold your color combo and reference that rather than having the duplicated list throughout your code base. Not much better but at least a change then only requires touching a single file.
Edit 1: The above is still true as of 24.2.1
Best solution for me in this case was to extend SwipeRefreshLayout and set the colors there, then use this class in xml or code when needed.
public class ColoredSwipeRefreshLayout extends SwipeRefreshLayout {
public ColoredSwipeRefreshLayout(@NonNull Context context) {
super(context);
setColors();
}
public ColoredSwipeRefreshLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setColors();
}
private void setColors() {
setColorSchemeColors(
ContextCompat.getColor(getContext(), R.color.blue_main),
ContextCompat.getColor(getContext(), R.color.blue_accent),
ContextCompat.getColor(getContext(), R.color.blue_dark));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With