앱에 스와이프하여 새로고침 추가
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Compose 사용해 보기
Jetpack Compose는 Android에 권장되는 UI 도구 키트입니다. Compose에서 풀 투 리프레시를 사용하는 방법을 알아보세요.
스와이프하여 새로고침 사용자 인터페이스 패턴은 수직 스와이프를 감지하고 고유한 진행률 표시줄을 표시하고 앱에서 콜백 메서드를 트리거하는 SwipeRefreshLayout
위젯에서 전적으로 구현됩니다. 레이아웃 파일에 위젯을 ListView
또는 GridView
의 상위 요소로 추가하고 사용자가 스와이프할 때 호출되는 새로고침 동작을 구현하여 이 동작을 사용 설정합니다.
이 페이지에서는 기존 레이아웃에 위젯을 추가하는 방법을 보여줍니다. 또한 스와이프 동작을 사용할 수 없는 사용자가 외부 기기로 수동 업데이트를 트리거할 수 있도록 작업 모음 오버플로 영역에 새로고침 작업을 추가하는 방법도 보여줍니다.
SwipeRefreshLayout 종속 항목 추가
앱에서 SwipeRefreshLayout
를 사용하려면 build.gradle
파일에 다음 종속 항목을 추가합니다.
Groovy
dependencies {
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01"
}
Kotlin
dependencies {
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
}
스와이프하여 새로고침하는 위젯을 기존 앱에 추가하려면 SwipeRefreshLayout
을 단일 ListView
또는 GridView
의 상위 요소로 추가합니다.
SwipeRefreshLayout
은 단일 ListView
또는 GridView
하위 요소만 지원합니다.
다음 예는 ListView
가 포함된 기존 레이아웃 파일에 SwipeRefreshLayout
위젯을 추가하는 방법을 보여줍니다.
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
ListFragment
와 함께 SwipeRefreshLayout
위젯을 사용할 수도 있습니다. 레이아웃에 ID가 "@android:id/list"
인 ListView
가 포함되어 있다면 스와이프하여 새로고침하는 기능은 자동으로 지원됩니다. 하지만, 이러한 방식을 사용하여 ListView
를 명시적으로 선언하면 기본 ListFragment
뷰 구조가 대체됩니다. 기본 뷰 구조를 사용하려면 SwipeRefreshLayout
및 ListFragment
동작 일부를 재정의합니다.
작업 모음에 새로고침 작업 추가
스와이프 동작을 실행할 수 없는 사용자가 수동 업데이트를 트리거할 수 있도록 앱의 작업 모음에 새로고침 작업을 추가합니다. 예를 들어 접근성 요구사항이 있는 사용자는 키보드 및 D패드와 같은 외부 기기를 사용하여 작업 모음 작업을 트리거할 수 있습니다.
android:showAsAction=never
속성을 설정하여 새로고침 작업을 버튼이 아닌 메뉴 항목으로 추가합니다. 작업을 버튼으로 표시하면 사용자가 새로고침 버튼 작업이 스와이프하여 새로고침하는 작업과 다르다고 생각할 수 있습니다. 작업 모음에서 새로고침 작업을 덜 눈에 띄게 만들어 D패드 사용자가 찾을 수 있는 장소에 액세스 가능한 옵션을 유지하면서 사용자가 스와이프 동작으로 수동 업데이트를 실행하도록 유도할 수 있습니다.
다음 코드는 오버플로 영역에 스와이프하여 새로고침 작업을 추가하는 방법을 보여줍니다.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_refresh"
android:showAsAction="never"
android:title="@string/menu_refresh"/>
</menu>
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[],[],null,["# Add swipe-to-refresh to your app\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to pull to refresh in Compose. \n[Pull to refresh in Compose →](/develop/ui/compose/components/pull-to-refresh) \n\nThe swipe-to-refresh user interface pattern is implemented entirely within the\n[SwipeRefreshLayout](/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout)\nwidget, which detects the vertical swipe, displays a distinctive progress bar, and triggers callback\nmethods in your app. Enable this behavior by adding the widget to your layout file as the parent of\na [ListView](/reference/android/widget/ListView) or\n[GridView](/reference/android/widget/GridView) and implementing the\nrefresh behavior that is invoked when the user swipes.\n\nThis page shows how to add the widget to an existing layout. It also shows how to add a refresh\naction to the action bar overflow area so that users who can't use the swipe gesture can trigger a\nmanual update with an external device.\n\nAdd SwipeRefreshLayout dependency\n---------------------------------\n\nTo use `SwipeRefreshLayout` in your app, add the following dependency to your\n`build.gradle` file: \n\n### Groovy\n\n```groovy\ndependencies {\n implementation \"androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01\"\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n implementation(\"androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01\")\n}\n```\n\nAdd the SwipeRefreshLayout Widget\n---------------------------------\n\nTo add the swipe-to-refresh widget to an existing app, add `SwipeRefreshLayout` as the\nparent of a single `ListView` or `GridView`.\n`SwipeRefreshLayout` only supports a single `ListView` or\n`GridView` child.\n\nThe following example demonstrates how to add the `SwipeRefreshLayout` widget to an\nexisting layout file containing a `ListView`: \n\n```xml\n\u003candroidx.swiperefreshlayout.widget.SwipeRefreshLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:id=\"@+id/swiperefresh\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\u003e\n\n \u003cListView\n android:id=\"@android:id/list\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\" /\u003e\n\n\u003c/androidx.swiperefreshlayout.widget.SwipeRefreshLayout\u003e\n```\n\nYou can also use the `SwipeRefreshLayout` widget with a\n[ListFragment](/reference/androidx/fragment/app/ListFragment). If the\nlayout contains a `ListView` with the ID `\"@android:id/list\"`, the\nswipe-to-refresh functionality is automatically supported. However, explicitly declaring the\n`ListView` this way supersedes the default `ListFragment` view structure. If\nyou want to use the default view structure, override parts of the `SwipeRefreshLayout`\nand `ListFragment` behavior.\n\nAdd a refresh action to the action bar\n--------------------------------------\n\nAdd a refresh action to your app's action bar so users who can't perform swipe gestures can\ntrigger a manual update. For example, users with accessibility needs can trigger action bar actions\nusing external devices, such as keyboards and D-pads.\n\nAdd the refresh action as a menu item, rather than as a button, by setting the attribute\n`android:showAsAction=never`. If you display the action as a button, users might assume\nthe refresh button action is different from the swipe-to-refresh action. Making the refresh action\nless conspicuous in the action bar encourages users to perform manual updates with swipe gestures\nwhile maintaining the accessible option where D-pad users look for it.\n\nThe following code demonstrates how to add the swipe-to-refresh action to the overflow area: \n\n```xml\n\u003cmenu xmlns:android=\"http://schemas.android.com/apk/res/android\" \u003e\n \u003citem\n android:id=\"@+id/menu_refresh\"\n android:showAsAction=\"never\"\n android:title=\"@string/menu_refresh\"/\u003e\n\u003c/menu\u003e\n```"]]