Search in sources :

Example 1 with MaterialHeader

use of com.scwang.smartrefresh.header.MaterialHeader in project SmartRefreshLayout by scwang90.

the class AssignCodeExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_assign_code);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    // 设置 Header 为 Material风格
    refreshLayout.setRefreshHeader(new MaterialHeader(this).setShowBezierWave(true));
    // 设置 Footer 为 球脉冲
    refreshLayout.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.Scale));
    /*
         * 以下代码仅仅为了演示效果而已,不是必须的
         */
    // 设置主题颜色
    refreshLayout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
    if (isFirstEnter) {
        isFirstEnter = false;
        // 触发上拉加载
        refreshLayout.autoLoadMore(250, 250, 1.5f);
        // 通过多功能监听接口实现 在第一次加载完成之后 自动刷新
        refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

            @Override
            public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
                if (oldState == RefreshState.LoadFinish && newState == RefreshState.None) {
                    refreshLayout.autoRefresh();
                    refreshLayout.setOnMultiPurposeListener(null);
                }
            }

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.finishLoadMore(2000);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.finishRefresh(3000);
            }
        });
    }
}
Also used : MaterialHeader(com.scwang.smartrefresh.header.MaterialHeader) SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar) BallPulseFooter(com.scwang.smartrefresh.layout.footer.BallPulseFooter)

Aggregations

Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 MaterialHeader (com.scwang.smartrefresh.header.MaterialHeader)1 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)1 RefreshState (com.scwang.smartrefresh.layout.constant.RefreshState)1 BallPulseFooter (com.scwang.smartrefresh.layout.footer.BallPulseFooter)1 SimpleMultiPurposeListener (com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener)1