여러 Android 버전에서 알림이 최적의 상태로 표시되도록 하려면
표준 알림 사용
템플릿을 사용하여
있습니다. 알림에 더 많은 콘텐츠를 제공하려면
확장 가능한 알림 기능을 사용해 보세요.
템플릿을 참조하세요.
하지만 시스템 템플릿이 필요에 맞지 않는 경우 자체 템플릿을
나타냅니다.
콘텐츠 영역의 맞춤 레이아웃 만들기
맞춤 레이아웃이 필요한 경우
NotificationCompat.DecoratedCustomViewStyle 드림
추가할 수 있습니다. 이 API를 사용하면 콘텐츠의 맞춤 레이아웃을 제공할 수 있습니다.
일반적으로 제목과 텍스트 콘텐츠가 차지하고
알림 아이콘, 타임스탬프, 하위 텍스트, 작업 버튼의 장식입니다.
이 API는 기본 알림을 기반으로 작성되어 확장 가능한 알림 템플릿과 유사하게 작동합니다.
레이아웃은 다음과 같습니다.
valnotificationManager=getSystemService(Context.NOTIFICATION_SERVICE)asNotificationManager// Get the layouts to use in the custom notification.valnotificationLayout=RemoteViews(packageName,R.layout.notification_small)valnotificationLayoutExpanded=RemoteViews(packageName,R.layout.notification_large)// Apply the layouts to the notification.valcustomNotification=NotificationCompat.Builder(context,CHANNEL_ID).setSmallIcon(R.drawable.notification_icon).setStyle(NotificationCompat.DecoratedCustomViewStyle()).setCustomContentView(notificationLayout).setCustomBigContentView(notificationLayoutExpanded).build()notificationManager.notify(666,customNotification)
자바
NotificationManagernotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);// Get the layouts to use in the custom notificationRemoteViewsnotificationLayout=newRemoteViews(getPackageName(),R.layout.notification_small);RemoteViewsnotificationLayoutExpanded=newRemoteViews(getPackageName(),R.layout.notification_large);// Apply the layouts to the notification.NotificationcustomNotification=newNotificationCompat.Builder(context,CHANNEL_ID).setSmallIcon(R.drawable.notification_icon).setStyle(newNotificationCompat.DecoratedCustomViewStyle()).setCustomContentView(notificationLayout).setCustomBigContentView(notificationLayoutExpanded).build();notificationManager.notify(666,customNotification);
알림의 배경 색상은 기기마다 다를 수 있습니다.
확인할 수 있습니다 다음과 같은 지원 라이브러리 스타일을 적용합니다.
TextAppearance_Compat_Notification: 텍스트
맞춤 레이아웃의 제목: TextAppearance_Compat_Notification_Title
다음 예와 같이 됩니다. 이 스타일은 색상 변화에 맞춰 조정되므로
검은색 바탕에 검은색 바탕에 검은색 바탕에 흰색 바탕에 흰색 텍스트로 표시되지 않습니다.
사용자가 앱을 사용하는 동안 알림을 트리거하면 결과는 다음과 같습니다.
그림 1과 유사합니다.
그림 1. 작은 알림 레이아웃이 표시됩니다.
다른 앱을 사용할 때
확인할 수 있습니다
확장 화살표를 탭하면 그림 2와 같이 알림이 펼쳐집니다.
그림 2. 큰 알림 레이아웃 표시
다른 앱을 사용할 때
확인할 수 있습니다
알림 제한 시간이 초과되면 알림은
시스템 표시줄(그림 3 참고)
그림 3. 작은 알림 레이아웃
시스템 표시줄에 표시됩니다.
확장 화살표를 탭하면 그림 4와 같이 알림이 펼쳐집니다.
그림 4. 큰 알림 레이아웃은
시스템 표시줄로 이동합니다.
완전한 맞춤 알림 레이아웃 만들기
알림을 표준 알림으로 장식하고 싶지 않은 경우
아이콘 및 헤더가 있는 경우 이전 단계를 따르되 setStyle()를 호출하지 마세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(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-27(UTC)"],[],[],null,["# Create a custom notification layout\n\nTo make your notifications look their best across different versions of Android,\nuse the [standard notification\ntemplate](/training/notify-user/build-notification) to build your\nnotifications. If you want to provide more content in your notification,\nconsider using one of the [expandable notification\ntemplates](/training/notify-user/expanded).\n\nHowever, if the system templates don't meet your needs, you can use your own\nlayout for the notification.\n| **Caution:** When using a custom notification layout, take special care to ensure your custom layout works with different device orientations and resolutions. Although this advice applies to all UI layouts, it's especially important for notifications because the space in the notification drawer is restricted. The height available for a custom notification layout depends on the Android version. On some versions, collapsed view layouts are limited to as little as 48 dp, heads-up view layouts are limited to as little as 88 dp, and expanded view layouts are limited to as little as 252 dp.\n\nCreate custom layout for the content area\n-----------------------------------------\n\nIf you need a custom layout, you can apply\n[`NotificationCompat.DecoratedCustomViewStyle`](/reference/androidx/core/app/NotificationCompat.DecoratedCustomViewStyle)\nto your notification. This API lets you provide a custom layout for the content\narea normally occupied by the title and text content, while still using system\ndecorations for the notification icon, timestamp, sub-text, and action buttons.\n\nThis API works similarly to the [expandable notification templates](/training/notify-user/expanded) by building on the basic notification\nlayout as follows:\n\n1. Build a [basic notification](/training/notify-user/build-notification) with [`NotificationCompat.Builder`](/reference/androidx/core/app/NotificationCompat.Builder).\n2. Call [`setStyle()`](/reference/androidx/core/app/NotificationCompat.Builder#setStyle(androidx.core.app.NotificationCompat.Style)), passing it an instance of [`NotificationCompat.DecoratedCustomViewStyle`](/reference/androidx/core/app/NotificationCompat.DecoratedCustomViewStyle).\n3. Inflate your custom layout as an instance of [`RemoteViews`](/reference/android/widget/RemoteViews).\n4. Call [`setCustomContentView()`](/reference/androidx/core/app/NotificationCompat.Builder#setCustomContentView(android.widget.RemoteViews)) to set the layout for the collapsed notification.\n5. Optionally, also call [`setCustomBigContentView()`](/reference/androidx/core/app/NotificationCompat.Builder#setCustomBigContentView(android.widget.RemoteViews)) to set a different layout for the expanded notification.\n\n| **Note:** If you're creating a customized notification for media playback controls, follow the same recommendations but use the `NotificationCompat.DecoratedMediaCustomViewStyle` class instead.\n\n### Prepare the layouts\n\nYou need a `small` and `large` layout. For this example, the `small` layout\nmight look like this: \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cLinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n android:orientation=\"vertical\"\u003e\n\n \u003cTextView\n android:id=\"@+id/notification_title\"\n style=\"@style/TextAppearance.Compat.Notification.Title\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"0dp\"\n android:layout_weight=\"1\"\n android:text=\"Small notification, showing only a title\" /\u003e\n \u003c/LinearLayout\u003e\n\nAnd the `large` layout might look like this: \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cLinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"300dp\"\n android:orientation=\"vertical\"\u003e\n\n \u003cTextView\n android:id=\"@+id/notification_title\"\n style=\"@style/TextAppearance.Compat.Notification.Title\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:layout_weight=\"1\"\n android:text=\"Large notification, showing a title and a body.\" /\u003e\n\n \u003cTextView\n android:id=\"@+id/notification_body\"\n style=\"@style/TextAppearance.Compat.Notification.Line2\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:layout_weight=\"1\"\n android:text=\"This is the body. The height is manually forced to 300dp.\" /\u003e\n \u003c/LinearLayout\u003e\n\n### Build and show the notification\n\nAfter the layouts are ready, you can use them as shown in the following example: \n\n### Kotlin\n\n```kotlin\nval notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager\n\n// Get the layouts to use in the custom notification.\nval notificationLayout = RemoteViews(packageName, R.layout.notification_small)\nval notificationLayoutExpanded = RemoteViews(packageName, R.layout.notification_large)\n\n// Apply the layouts to the notification.\nval customNotification = NotificationCompat.Builder(context, CHANNEL_ID)\n .setSmallIcon(R.drawable.notification_icon)\n .setStyle(NotificationCompat.DecoratedCustomViewStyle())\n .setCustomContentView(notificationLayout)\n .setCustomBigContentView(notificationLayoutExpanded)\n .build()\n\nnotificationManager.notify(666, customNotification)\n```\n\n### Java\n\n```java\nNotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);\n\n// Get the layouts to use in the custom notification\nRemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);\nRemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_large);\n\n// Apply the layouts to the notification.\nNotification customNotification = new NotificationCompat.Builder(context, CHANNEL_ID)\n .setSmallIcon(R.drawable.notification_icon)\n .setStyle(new NotificationCompat.DecoratedCustomViewStyle())\n .setCustomContentView(notificationLayout)\n .setCustomBigContentView(notificationLayoutExpanded)\n .build();\n\nnotificationManager.notify(666, customNotification);\n```\n\nBe aware that the background color for the notification can vary across devices\nand versions. Apply Support Library styles such as\n`TextAppearance_Compat_Notification` for the text and\n`TextAppearance_Compat_Notification_Title` for the title in your custom layout,\nas shown in the following example. These styles adapt to the color variations so\nyou don't end up with black-on-black or white-on-white text. \n\n```xml\n\u003cTextView\n android:layout_width=\"wrap_content\"\n android:layout_height=\"match_parent\"\n android:layout_weight=\"1\"\n android:text=\"@string/notification_title\"\n android:id=\"@+id/notification_title\"\n style=\"@style/TextAppearance.Compat.Notification.Title\" /\u003e\n```\n\nAvoid setting a background image on your `RemoteViews` object, because your text\nmight become unreadable.\n\nWhen you trigger a notification while the user is using an app, the result is\nsimilar to figure 1:\n**Figure 1.** A small notification layout appears while using other apps.\n\nTapping the expander arrow expands the notification, as shown in figure 2:\n**Figure 2.** A large notification layout appears while using other apps.\n\nAfter the notification timeout runs out, the notification is visible only in the\nsystem bar, which looks like figure 3:\n**Figure 3.** How the small notification layout appears in the system bar.\n\nTapping the expander arrow expands the notification, as shown in figure 4:\n**Figure 4.** A large notification layout appears in the system bar.\n\nCreate a fully custom notification layout\n-----------------------------------------\n\n| **Note:** Apps targeting [Android\n| 12](/about/versions/12/behavior-changes-12#custom-notifications) (API level 31) or later can't create fully custom notifications. Instead, the system applies a standard template nearly identical to the behavior of [`Notification.DecoratedCustomViewStyle`](/reference/android/app/Notification.DecoratedCustomViewStyle).\n\nIf you don't want your notification decorated with the standard notification\nicon and header, follow the preceding steps but *don't* call `setStyle()`.\n| **Caution:** We don't recommend using an undecorated notification as this doesn't match other notifications and can cause significant layout compatibility issues on devices that apply different styling to the notification area."]]