ProgressBar under Action Bar

前端 未结 6 2087
终归单人心
终归单人心 2020-11-28 01:18

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

Details:

6条回答
  •  自闭症患者
    2020-11-28 01:35

    This is now a native behavior that can be obtained using SwipeRefreshLayout.

    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.

提交回复
热议问题