android WebView swipe refresh
build.gradle
dependencies { implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' }
activity_main.xml
<RelativeLayout 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" tools:context=".MainActivity"> <androidx.swiperefreshlayout.widget.SwipeRefreshLayout android:id="@+id/swipe" android:layout_width="match_parent" android:layout_height="match_parent"> <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"/> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity { private WebView webView; private SwipeRefreshLayout swipeRefreshLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); webView = findViewById(R.id.webView); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swipeRefreshLayout.setRefreshing(true); new Handler().postDelayed(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(false); webView.reload(); } },3000); } }); swipeRefreshLayout.setColorSchemeColors( getResources().getColor(R.color.orange) ); } }