반응형

build.gradle 파일에 dependency추가 

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

 

Layout에 SwipeRefreshLayout 추가

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swiperefreshlayout"
    tools:context=".MainActivity">

    <com.example.toonview.CustomWebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

java 파일에 setOnRefreshListener 추가하여  필요한 기능 구현

swipeRefreshLayout = findViewById(R.id.swiperefreshlayout);

swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
        wView.reload();
        swipeRefreshLayout.setRefreshing(false);
    }
});

 

반응형

+ Recent posts