使用Android系统自带的下拉刷新控件
16lz
2021-12-04
首先布局:
<?xml version="1.0" encoding="utf-8"?>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" >Activity中调用android:layout_width="wrap_content" android:layout_height="wrap_content"> android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我是系统自带的下拉刷新控件" android:gravity="center"/>
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);//取消刷新 } }}
更多相关文章
- android SpannableString使用详解
- android SwipeRefreshLayout 下拉刷新控件使用
- Android下拉刷新,上拉加载
- Android中颜色透明度对应16进制值
- Android(安卓)搜索到的关键字改变颜色
- android ActionBar的使用
- android 如何从sqlite读取数据到spinner下拉中显示
- android 按钮按下时改变字体颜色
- Android(安卓)常用的ui(单选框 多选框 下拉列表框 拖动条)