使用Android系统自带的下拉刷新控件

news/2024/7/6 6:30:27

首先布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:id="@+id/refresh"
    android:layout_height="match_parent"
    >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="我是系统自带的下拉刷新控件"
                android:gravity="center"/>

         </ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
Activity中调用

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
    private SwipeRefreshLayout refresh;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);
        //设置下拉刷新的箭头颜色
        refresh.setColorSchemeResources(android.R.color.holo_red_light);
        //设置下拉刷新的背景颜色为白色
        refresh.setProgressBackgroundColorSchemeResource(android.R.color.white);


        refresh.setOnRefreshListener(this);
        refresh.setOnRefreshListener(this);
    }

    @Override
    public void onRefresh() {
        Toast.makeText(this, "下拉刷新成功", Toast.LENGTH_SHORT).show();
        if (refresh.isRefreshing()) {//如果正在刷新
            refresh.setRefreshing(false);//取消刷新
        }
    }
}



http://www.niftyadmin.cn/n/3649186.html

相关文章

Django Admin Site (v1.4) 的Nginx配置

本人写本文是因为发现在使用NginxApache搭建完Django站点后&#xff0c;admin site显示的很丑陋。查看源码后发现&#xff0c;admin的css、js和图片都无法正常显示 baidu了一些资料&#xff0c;操作下来也不成功&#xff0c;可能是Django的版本更新的关系。所以自己写一下配置…

AIX 程序设计大赛---AIX正方形问题

AIX 程序设计大赛---AIX正方形问题作者&#xff1a;成晓旭作为“算法及实现”栏目的“抛砖引玉”之作&#xff0c;将自己2年多前实现的一个算法放出来。有一年IBM出了这个Java程序设计竞赛题&#xff0c;当时&#xff0c;自己花晚上时间用Java实现了。[问题描述]:任意给定一个正…

bootstrap4侧边栏_如何使用纯CSS和Bootstrap 4构建多个堆叠式粘性侧边栏

bootstrap4侧边栏In this tutorial you’ll work on building multiple sticky sidebars that stack without using any JavaScript. 在本教程中&#xff0c;您将构建无需使用任何JavaScript即可堆叠的多个粘性侧栏。 We’ll discuss: 我们将讨论&#xff1a; Multiple Stack…

textView相关知识

一、给textview设置颜色为#fffff 有时候我们会从服务器获得数据&#xff0c;但是后台给的服务器的值是比如&#xff1a;#B373FB 此时要想给TextView设置文字直接设置textview.setTextColor();是不行的。此时我们可以这样 String str floorcolor; int id Color.parseColor(s…

PYthon 转换HTML到Text纯文本

今天项目需要将HTML转换为纯文本&#xff0c;去网上搜了一下&#xff0c;发现Python果然是神通广大&#xff0c;无所不能&#xff0c;方法是五花八门。。。 拿今天亲自试的两个方法举例&#xff0c;以方便后人&#xff1a; 方法一&#xff1a; 1. 安装nltk&#xff0c;可以去…

如何使用vue-router设置Vue.js身份验证和路由处理

介绍 (Introduction) Vue.js is a progressive JavaScript framework for building front-end applications. Coupled with vue-router, we can build high performance applications with complete dynamic routes. Vue-router is an efficient tool and can efficiently hand…

Delphi之东进模拟语音卡(D160A)可复用源码

Delphi之东进模拟语音卡(D160A)可复用源码作者&#xff1a;成晓旭Blog&#xff1a;http://blog.csdn.net/cxxsoft(声明&#xff1a;欢迎转载&#xff0c;请保证文章的完整性)设计简介&#xff1a;1、 将卡、通道分别单独进行设计与封装。2、 所有的外部操作接口都封装在卡类…

友盟多渠道打包

1.按照umeng的要求&#xff0c;manifest文件中需要有 这段配置&#xff0c;value那里就是wandoujia&#xff0c;360之类的渠道名称&#xff0c;但是我们在这里不会去写渠道名&#xff0c;写的是一个占位符&#xff0c;后面gradle编译的时候会动态的替换掉它。 <meta-dataa…