操作栏下的进度条 [英] ProgressBar under Action Bar

查看:33
本文介绍了操作栏下的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题摘要:如何将 ProgressBar 集成到 ActionBar 中,就像在 Chrome 应用中一样?

Question Summary: How can I make a ProgressBar integrated inside the ActionBar, like on the Chrome App?

详细信息:在 Chrome 中查看此屏幕截图:

Details: Look at this screenshot from Chrome:

我想像这样创建一个操作栏.就在操作栏下方,有一个根据页面加载填充的 ProgressBar.我已经从很多应用程序中看到了这个例子,比如 Feedly,但我一直无法创建自己的实现.我尝试使用 Android 自己的 API 来创建它:

I want to create an Action Bar just like this. Just under the Action Bar, there's a ProgressBar that fills according to page load. I've seen this example from many apps, like Feedly, but I haven't been able to create my own implementation. I tried using Android's own APIs to create it:

@Override
protected void onCreate(Bundle savedInstanceState) {
    //Request Permission to display the Progress Bar...
    this.requestWindowFeature(Window.FEATURE_PROGRESS);
            this.setWindowContentView(R.layout.activity_main)
    super.onCreate(savedInstanceState);

    this.setProgressBarIndeterminate(true);
}

但这段代码只会使 ProgressBar 显示超过操作栏,如下所示:

But this code only causes the ProgressBar to show over the Action Bar, like so:

那么,如何让我的 ProgressBar 出现在操作栏下,就像在 Chrome 应用上一样?

So, how can I make my ProgressBar appear under the Action Bar, like on the Chrome App?

推荐答案

这现在是可以使用 SwipeRefreshLayout.

你可以用 SwipeRefreshLayout 包裹你的可滚动视图,然后你只需要监听 onRefresh 事件:

You can wrap your scrollable view with a SwipeRefreshLayout and then you just need to listen to onRefresh events:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    swipeLayout.setOnRefreshListener(this);
    swipeLayout.setColorScheme(android.R.color.holo_blue_bright, 
            android.R.color.holo_green_light, 
            android.R.color.holo_orange_light, 
            android.R.color.holo_red_light);
}


@Override public void onRefresh() {
    new Handler().postDelayed(new Runnable() {
        @Override public void run() {
            swipeLayout.setRefreshing(false);
        }
    }, 5000);
}

可以在此博客中找到一个不错的简单教程.

A nice and simple tutorial can be found in this blog.

这篇关于操作栏下的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆