// Set app's grammatical gender to femininevalgIM=mContext.getSystemService(GrammaticalInflectionManager::class.java)gIM.setRequestedApplicationGrammaticalGender(Configuration.GRAMMATICAL_GENDER_FEMININE)
Java
// Set app's grammatical gender to feminineGrammaticalInflectionManagergIM=mContext.getSystemService(GrammaticalInflectionManager.class);gIM.setRequestedApplicationGrammaticalGender(Configuration.GRAMMATICAL_GENDER_FEMININE);
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Personalize your app's UI with grammatical gender\n\n3 billion people speak *gendered languages* : languages where grammatical\ncategories---such as nouns, verbs, adjectives, and prepositions---inflect according\nto the gender of people and objects you talk to or about. Traditionally, many\ngendered languages use masculine grammatical gender as the default or *generic*\ngender.\n\nAddressing users in the wrong grammatical gender, such as addressing women in\nmasculine grammatical gender, can [negatively impact](https://www.nature.com/articles/s41539-021-00087-7)\ntheir performance and attitude. In contrast, a UI with language that correctly\nreflects the user's grammatical gender can improve user engagement and provide\na more personalized and natural-sounding user experience.\n\nTo help you build a user-centric UI for gendered languages, Android 14\nintroduces the Grammatical Inflection API, which lets you add support for\ngrammatical gender without refactoring your app.\n\nExample of inflection for grammatical gender\n--------------------------------------------\n\nIn gendered languages, grammatical gender can't be worked around the same way as\nit can in English. For example, in English to write a message telling the user\nthat they are subscribed to your app's service, you could use a single phrase:\n\"You are subscribed to...\".\n\nTo provide a similar phrase in French, there are a few options:\n\n- Masculine-inflected form: \"Vous êtes abonné à...\" (English: \"You are subscribed to...\")\n- Feminine-inflected form: \"Vous êtes abonnée à...\" (English: \"You are subscribed to...\")\n- Neutral phrasing that avoids inflection: \"Abonnement à...activé\" (English: \"Subscription to ... enabled\")\n\nSimilar to English, the first two options address the user directly. However,\nwithout any mechanism to accommodate this grammatical feature of French, you\nwould only have the third option, which changes the tone of the message and\nmight not be what you want to display in your user interface.\n\nIn these cases, the Grammatical Inflection API lowers the effort to display\nstrings relative to the viewer's grammatical gender---that is, the person who's\nviewing the UI, not who's being talked about. To show users personalized\ntranslations in your app, [add translations that are inflected for each\ngrammatical gender](#add-translations) for affected languages and then use the\n[`GrammaticalInflectionManager`](/reference/android/app/GrammaticalInflectionManager) API to adjust which translations are shown\nto each user.\n| **Note:** Support for these resource qualifiers is only available in [Android\n| Studio Giraffe Canary 7](/studio/preview/features#grammatical-inflection-api) or higher.\n\nIn many languages, grammatical gender also applies to regular nouns in addition\nto people. For example, in French the word chaise (chair) is feminine, whereas\noiseau (bird) is masculine. For situations other than addressing the user, you\ncan use the existing [ICU SelectFormat](/reference/android/icu/text/SelectFormat) API.\n\nImplement the API\n-----------------\n\nAfter the user has indicated their grammatical gender (for example, either\nthrough a settings section of your app or a user setup workflow), you can use\nthe [`setRequestedApplicationGrammaticalGender(int)`](/reference/android/app/GrammaticalInflectionManager#setRequestedApplicationGrammaticalGender(int)) method to store the\nvalue in your app's resources configuration.\n\nFor example, if you want to set a user's preferred grammatical gender to\nfeminine, you would ask the user to select which grammatical gender they prefer\nand then call the API: \n\n### Kotlin\n\n```kotlin\n// Set app's grammatical gender to feminine\nval gIM = mContext.getSystemService(GrammaticalInflectionManager::class.java)\ngIM.setRequestedApplicationGrammaticalGender(\n Configuration.GRAMMATICAL_GENDER_FEMININE)\n```\n\n### Java\n\n```java\n// Set app's grammatical gender to feminine\nGrammaticalInflectionManager gIM =\n mContext.getSystemService(GrammaticalInflectionManager.class);\ngIM.setRequestedApplicationGrammaticalGender(\n Configuration.GRAMMATICAL_GENDER_FEMININE);\n```\n| **Caution:** Calling `setRequestedApplicationGrammaticalGender()` recreates your `Activity`, unless your app handles `grammaticalGender` configuration changes by itself.\n\nHere is example of how to declare [configuration changes](/guide/topics/resources/runtime-changes) in your app's\nmanifest file if you want to handle them yourself: \n\n \u003cactivity android:name=\".TestActivity\"\n android:configChanges=\"grammaticalGender\"\n android:exported=\"true\"\u003e\n \u003c/activity\u003e\n\nIf your app needs to check the grammatical gender in the current resource\nconfiguration, you can use the [`getApplicationGrammaticalGender()`](/reference/android/app/GrammaticalInflectionManager#getApplicationGrammaticalGender()) method\nto retrieve it: \n\n### Kotlin\n\n```kotlin\nval gIM = mContext.getSystemService(GrammaticalInflectionManager::class.java)\nval grammaticalGender = gIM.getApplicationGrammaticalGender()\n```\n\n### Java\n\n```java\nGrammaticalInflectionManager gIM =\n mContext.getSystemService(GrammaticalInflectionManager.class);\nint grammaticalGender = gIM.getApplicationGrammaticalGender();\n```\n\nAdd translations for languages with grammatical gender\n------------------------------------------------------\n\nTo provide localized text for languages with grammatical gender, [create an\nalternative resources file](/guide/topics/resources/providing-resources#AlternativeResources) and append the grammatical gender qualifier\nimmediately after the locale name for those languages. The following table\noutlines the possible values:\n\n| Qualifier | String value | Example (French `fr`) |\n|-----------|--------------|---------------------------------------|\n| Feminine | `feminine` | `res/values-fr-feminine/strings.xml` |\n| Masculine | `masculine` | `res/values-fr-masculine/strings.xml` |\n| Neuter | `neuter` | `res/values-fr-neuter/strings.xml` |\n\nYou should only include strings that support grammatical gender inflections in\nthese resources files. All strings must have a value in the [default resource\nfile that contains other localized strings](/guide/topics/resources/localization#creating-alternatives). This default translation is\nshown whenever a gender-inflected translation is not available.\n\nIn the [example provided for French earlier](#inflection), the neutral phrasing would be\nthe value of the string in the default resources `res/values-fr/strings.xml`\nfile. The following code snippets show how each resource file would be formatted\nto accommodate all the grammatical variations from the example in French: \n\n### Feminine\n\n\nInclude the feminine-inflected string in the `res/values-fr-feminine/strings.xml` resources file: \n\n```xml\n\u003cresources\u003e\n ...\n \u003cstring name=\"example_string\"\u003eVous êtes abonnée à...\u003c/string\u003e\n\u003c/resources\u003e\n```\n\n### Masculine\n\n\nInclude the masculine-inflected string in the `res/values-fr-masculine/strings.xml` resources file: \n\n```xml\n\u003cresources\u003e\n ...\n \u003cstring name=\"example_string\"\u003eVous êtes abonné à...\u003c/string\u003e\n\u003c/resources\u003e\n```\n\n### Neuter\n\n\nInclude the default string in the `res/values-fr/strings.xml` resources file: \n\n```xml\n\u003cresources\u003e\n ...\n \u003cstring name=\"example_string\"\u003eAbonnement à...activé\u003c/string\u003e\n\u003c/resources\u003e\n```"]]