如何在SwipeRefreshLayout中更改样式progerssbar?

时间:2014-11-27 03:44:32

标签: android android-layout

我使用SwipeRefreshLayout来更新我的列表。

一切正常。但我不喜欢进度条。它是圆的。并带着箭头旋转。我看过一些从中心到边缘移动的例子。如何设置进度条样式?

private SwipeRefreshLayout swipeLayout;
...
swipeLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_guest_list);
        swipeLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.CYAN);
        swipeLayout.setOnRefreshListener(this);

example我需要视频

4 个答案:

答案 0 :(得分:3)

您无法更改动画。

package com.example.ismab_000.myapplication.backend; import com.google.api.server.spi.config.Api; import com.google.api.server.spi.config.ApiMethod; import com.google.api.server.spi.config.ApiNamespace; import com.google.appengine.api.oauth.OAuthRequestException; import com.google.appengine.api.oauth.OAuthService; import com.google.appengine.api.oauth.OAuthServiceFactory; import com.google.appengine.api.users.User; import javax.inject.Named; /** * An endpoint class we are exposing */ @Api( name = "myApi", version = "v1", scopes = {Constants.EMAIL_SCOPE}, clientIds = {Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID,Constants.IOS_CLIENT_ID}, audiences = {Constants.ANDROID_AUDIENCE}, namespace = @ApiNamespace(ownerDomain = "backend.myapplication.ismab_000.example.com", ownerName = "backend.myapplication.ismab_000.example.com", packagePath = "")) public class MyEndpoint { User user = null; MyBean response = new MyBean(); String email; /** * A simple endpoint method that takes a name and says Hi back */ @ApiMethod(name = "sayHi") public MyBean sayHi(@Named("name") String name) { /* try { OAuthService oauth = OAuthServiceFactory.getOAuthService(); user = oauth.getCurrentUser(); } catch (OAuthRequestException e) { // The consumer made an invalid OAuth request, used an access token that was // revoked, or did not provide OAuth information. // ... response.setData("Hola desde Metodo1, " + name); } */ email= user.getEmail(); //response.setData("Hi, " + name + user.getEmail().toString()); response.setData("Hi, desde APYSAYHI..."); return response; } @ApiMethod(name = "Metodo1") public MyBean metodo1(@Named("name") String name) { response.setData("Hola desde Metodo1, " + name); return response; } @ApiMethod(name = "Metodo2") public MyBean metodo2(@Named("name") String name) { response.setData("Hola desde Metodo2, " + name); return response; } } 中,您无法自定义;我相信这是Google试图让开发人员坚持常见模式的尝试。你可以设计的样式是动画的四种颜色,用SwipeRefreshLayout指定。

setColorScheme()会为您显示其预定义动画。这可能是SwipeRefreshLayout返回false并且用户“下拉”或者设置canChildScrollUp()时。使用setRefreshing(true)关闭动画。将您的逻辑放在侦听器的方法setRefreshing(false)中。如果您在onRefreshing()中放置了不是canChildScrollUp()的内容,请覆盖ListView。你应该好好离开这里。

答案 1 :(得分:2)

您实际上可以通过提供参考将其更改为较旧的进度条一个 v4 库的旧jar文件。我在更新eclipse之后突然遇到同样的问题,我只是将旧的support-v4.jar复制到项目的libs文件夹中,然后使用项目属性引用这个support-v4.jar然后清理并构建项目,现在它使用了旧的类。 如果您没有使用更新的支持库中的任何特定内容,则此解决方案非常合适。

答案 2 :(得分:0)

这是我的例子

webframe = WebView

swipeContainer = swipeLayout

swipeContainer.setOnRefreshListener {
        webframe.reload()
        swipeContainer.isRefreshing = false
        swipeContainer.setColorSchemeColors(Color.WHITE)
        swipeContainer.setProgressBackgroundColorSchemeColor(Color.rgb(0,165,165))
    }

答案 3 :(得分:0)

您可以使用不同颜色的滑动进度var播放:

swipeRefreshLayout.setColorSchemeResources(R.color.blue, R.color.green, R.color.orange);

在colors.xml中定义了蓝色,绿色和橙色

setColorSchemeResources 会收到一个 varargs ,因此您可以在其中使用多种颜色