android androidx.swiperefreshlayout 刷新控件

今天碰到界面需要刷新的功能,於是找到了androidx.swiperefreshlayout 控件

使用步驟:

1、引用androidx.swiperefreshlayout 包,在app目錄下的build.gradle 添加如下:

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

2、在xml文件添加

<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/swipeRedreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal|center_vertical"
        android:text="TextView"
        android:textSize="30sp" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

3、activity使用

    private SwipeRefreshLayout swipeRefreshLayout;
  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

//        getAd();
        mContext = getContext();
        view = inflater.inflate(R.layout.fragment_con, container, false);

    swipeRefreshLayout = view.findViewById(R.id.sw_refresh);

  swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                searchWifi();
            }
        });

//取消刷新旋轉圖標
   swipeRefreshLayout.setRefreshing(false);


        return view;
    }

參考文檔:

https://blog.csdn.net/fjnu_se/article/details/106687692

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章