글꼴 리소스
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
글꼴 리소스는 앱에서 사용할 수 있는 맞춤 글꼴을 정의합니다. 글꼴은 개별 글꼴 파일 또는 글꼴 모음이라고 하는 글꼴 파일 모임일 수 있으며 XML로 정의됩니다.
또한, XML로 글꼴을 정의하는 방법을 참고하거나 다운로드 가능한 글꼴을 사용하세요.
번들 글꼴
글꼴은 앱 리소스로 묶을 수 있습니다. 글꼴은 R
파일에서 컴파일되고 자동으로 시스템에서 리소스로 사용할 수 있습니다. 그런 다음 font
리소스 유형의 도움을 받아 이 글꼴에 액세스할 수 있습니다.
- 파일 위치:
res/font/filename.ttf
(.ttf
, .ttc
, .otf
또는 .xml
)
파일 이름은 리소스 ID로 사용됩니다.- 리소스 참조:
- XML의 경우:
@[package:]font/font_name
- 문법:
-
<?xml version="1.0" encoding="utf-8"?>
<font-family>
<font
android:font="@[package:]font/font_to_include"
android:fontStyle=["normal" | "italic"]
android:fontWeight="weight_value" />
</font-family>
- 요소:
-
<font-family>
- 필수사항. 이 요소는 루트 노드여야 합니다.
속성 없음
<font>
- 글꼴 모음 내에 단일 글꼴을 정의합니다. 하위 노드를 포함하지 않습니다.
속성:
android:fontStyle
- 키워드. 글꼴 스타일을 정의합니다. 이 속성은 글꼴이 글꼴 스택에 로드되고 글꼴 헤더 표의 모든 스타일 정보를 재정의할 때 사용됩니다. 이 속성을 지정하지 않으면 앱은 글꼴 헤더 표의 값을 사용합니다. 상수 값은
normal
또는 italic
입니다.
android:fontWeight
- 정수. 글꼴의 두께입니다. 이 속성은 글꼴이 글꼴 스택으로 로드되고 글꼴의 헤더 표에 있는 모든 두께 정보를 재정의할 때 사용됩니다. 속성 값은 100에서 900까지 100의 배수여야 합니다. 이 속성을 지정하지 않으면 앱은 글꼴 헤더 표의 값을 사용합니다. 가장 일반적인 값은 일반 두께가 400, 굵은 체의 두께가 700입니다.
- 예:
res/font/lobster.xml
에 저장된 XML 파일:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/lobster_regular" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="@font/lobster_italic" />
</font-family>
res/layout/
에 저장된 XML 파일로, 글꼴을 TextView
에 적용합니다.
<?xml version="1.0" encoding="utf-8"?>
<EditText
android:fontFamily="@font/lobster"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World!" />
다운로드 가능한 글꼴
다운로드 가능한 글꼴 리소스는 앱에서 사용할 수 있는 맞춤 글꼴을 정의합니다. 이 글꼴은 앱 자체에서는 사용할 수 없습니다. 이 글꼴은 글꼴 제공업체에서 가져옵니다.
- 파일 위치:
res/font/filename.xml
파일 이름은 리소스 ID입니다.
- 리소스 참조:
- XML의 경우:
@[package:]font/font_name
- 문법:
-
<?xml version="1.0" encoding="utf-8"?>
<font-family
android:fontProviderAuthority="authority"
android:fontProviderPackage="package"
android:fontProviderQuery="query"
android:fontProviderCerts="@[package:]array/array_resource" />
- 요소:
-
<font-family>
- 필수사항. 이 요소는 루트 노드여야 합니다.
속성:
android:fontProviderAuthority
- 문자열. 필수사항. 글꼴 요청을 정의하는 글꼴 제공업체의 권한입니다.
android:fontProviderPackage
- 문자열. 필수사항. 요청에 사용될 글꼴 제공업체의 패키지 이름입니다. 제공업체의 ID를 확인하는 데 사용됩니다.
android:fontProviderQuery
- 문자열. 필수사항. 글꼴의 문자열 쿼리.
이 문자열의 형식에 관한 글꼴 제공업체의 문서를 참고하세요.
android:fontProviderCerts
- 배열 리소스. 필수사항. 이 제공업체에 서명하는 데 사용되는 인증서의 해시 집합을 정의합니다. 제공업체의 ID를 확인하는 데 사용되며 제공업체가 시스템 이미지의 일부가 아닌 경우에만 필요합니다. 값은 단일 목록(문자열 배열 리소스) 또는 목록 중 하나의 목록(배열 리소스)을 가리킬 수 있으며 각각의 개별 목록은 서명 해시 모음을 나타냅니다. 이러한 값은 글꼴 제공업체의 문서를 참고하세요.
- 예:
res/font/lobster.xml
에 저장된 XML 파일:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
android:fontProviderAuthority="com.example.fontprovider.authority"
android:fontProviderPackage="com.example.fontprovider"
android:fontProviderQuery="Lobster"
android:fontProviderCerts="@array/certs">
</font-family>
인증서 배열을 정의하는 res/values/
에 저장된 XML 파일입니다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="certs">
<item>MIIEqDCCA5CgAwIBAgIJA071MA0GCSqGSIb3DQEBBAUAMIGUMQsww...</item>
</string-array>
</resources>
res/layout/
에 저장된 XML 파일로, 글꼴을 TextView
에 적용합니다.
<?xml version="1.0" encoding="utf-8"?>
<EditText
android:fontFamily="@font/lobster"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World!" />
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 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,["# Font resources\n\nA font resource defines a custom font that you can use in your app. Fonts\ncan be individual font files or a collection of font files, known as a\nfont family and defined in XML.\n\nAlso see how to define [fonts\nin XML](/guide/topics/ui/look-and-feel/fonts-in-xml) or instead use [Downloadable Fonts](/guide/topics/ui/look-and-feel/downloadable-fonts).\n\nBundled font\n------------\n\n\nYou can bundle fonts as resources in an app. Fonts are compiled in the\n`R` file and are automatically available in the system as a\nresource. You can then access these fonts with the help of the\n`font` resource type.\n\nfile location:\n: `res/font/`*filename*`.ttf`\n (`.ttf`, `.ttc`, `.otf`, or\n `.xml`) \n\n The filename is used as the resource ID.\n\nresource reference:\n: In XML: `@[package:]font/`*font_name*\n\nsyntax:\n:\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cfont-family\u003e\n \u003cfont\n android:font=\"@[package:]font/font_to_include\"\n android:fontStyle=[\"normal\" | \"italic\"]\n android:fontWeight=\"weight_value\" /\u003e\n \u003c/font-family\u003e\n ```\n\nelements:\n:\n\n `\u003cfont-family\u003e`\n : **Required.** This must be the root node.\n\n No attributes.\n\n `\u003cfont\u003e`\n\n : Defines a single font within a family. Contains no child nodes. Attributes:\n\n `android:fontStyle`\n : *Keyword* . Defines the font style. This attribute is\n used when the font is loaded into the font stack and overrides\n any style information in the font's header tables. If you don't\n specify the attribute, the app uses the value from the font's\n header tables. The constant value is either\n `normal` or `italic`.\n\n `android:fontWeight`\n : *Integer*. The weight of the font. This attribute is\n used when the font is loaded into the font stack and overrides\n any weight information in the font's header tables. The\n attribute value must be a multiple\n of 100 between 100 and 900, inclusive. If you don't specify\n the attribute, the app uses the value from the font's header\n tables. The most common values are 400 for regular weight and 700\n for bold weight.\n\nexample:\n : XML file saved at `res/font/lobster.xml`: \n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cfont-family xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n \u003cfont\n android:fontStyle=\"normal\"\n android:fontWeight=\"400\"\n android:font=\"@font/lobster_regular\" /\u003e\n \u003cfont\n android:fontStyle=\"italic\"\n android:fontWeight=\"400\"\n android:font=\"@font/lobster_italic\" /\u003e\n \u003c/font-family\u003e\n ```\n\n XML file saved in `res/layout/` that applies the font to a\n [TextView](/reference/android/widget/TextView):\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cEditText\n android:fontFamily=\"@font/lobster\"\n android:layout_width=\"fill_parent\"\n android:layout_height=\"wrap_content\"\n android:text=\"Hello, World!\" /\u003e\n ```\n\nDownloadable font\n-----------------\n\n\nA downloadable font resource defines a custom font that you can use in an\napp. This font isn't available in the app itself. Instead, the font is\nretrieved from a font provider.\n\nfile location:\n: `res/font/`*filename*`.xml`\n The filename is the resource ID.\n\nresource reference:\n: In XML:`@[package:]font/`*font_name*\n\nsyntax:\n:\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cfont-family\n android:fontProviderAuthority=\"authority\"\n android:fontProviderPackage=\"package\"\n android:fontProviderQuery=\"query\"\n android:fontProviderCerts=\"@[package:]array/array_resource\" /\u003e\n ```\n\nelements:\n:\n\n `\u003cfont-family\u003e`\n : **Required.** This must be the root node.\n\n attributes:\n\n `android:fontProviderAuthority`\n : *String* . **Required**. The authority of the font\n provider that defines the font request.\n\n `android:fontProviderPackage`\n : *String* . **Required**. The package name of the font\n provider to be used for the request. This is used to verify the\n identity of the provider.\n\n `android:fontProviderQuery`\n : *String* . **Required**. The string query of the font.\n Refer to your font provider's documentation on the format of this\n string.\n\n `android:fontProviderCerts`\n : *Array resource* . **Required**. Defines the sets of\n hashes for the certificates used to sign this provider. This is\n used to verify the identity of the provider and is only required\n if the provider isn't part of the system image. The value can\n point to a single list (a string array resource) or a list of lists\n (an array resource), where each individual list represents one\n collection of signature hashes. Refer to your font provider's\n documentation for these values.\n\n\nexample:\n : XML file saved at `res/font/lobster.xml`: \n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cfont-family xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:fontProviderAuthority=\"com.example.fontprovider.authority\"\n android:fontProviderPackage=\"com.example.fontprovider\"\n android:fontProviderQuery=\"Lobster\"\n android:fontProviderCerts=\"@array/certs\"\u003e\n \u003c/font-family\u003e\n ```\n\n XML file saved in `res/values/` that defines the cert array:\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cresources\u003e\n \u003cstring-array name=\"certs\"\u003e\n \u003citem\u003eMIIEqDCCA5CgAwIBAgIJA071MA0GCSqGSIb3DQEBBAUAMIGUMQsww...\u003c/item\u003e\n \u003c/string-array\u003e\n \u003c/resources\u003e\n ```\n\n XML file saved in `res/layout/` that applies the font to a\n [TextView](/reference/android/widget/TextView):\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cEditText\n android:fontFamily=\"@font/lobster\"\n android:layout_width=\"fill_parent\"\n android:layout_height=\"wrap_content\"\n android:text=\"Hello, World!\" /\u003e\n ```"]]