تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يُجري نظام Android تغييرًا في الإعدادات في كل مرة يتم فيها ربط لوحة مفاتيح بجهاز أو فصلها عنه. لضمان تجربة مستخدم سلسة و
زيادة إنتاجية المستخدم إلى أقصى حد على الأجهزة ذات الشاشات الكبيرة والمزوّدة بلوحات مفاتيح قابلة للفصل،
يجب أن يدير تطبيقك تغييرات إعدادات لوحة المفاتيح بفعالية.
منع إعادة إنشاء النشاط عند تغيير لوحة المفاتيح
لمنع إعادة إنشاء نشاطك عند ربط لوحة مفاتيح قابلة للفصل أو فصلها، أضِف قيمًا ذات صلة بلوحة المفاتيح إلى سمة configChanges
في ملف بيان تطبيقك وأضِف عرضًا إلى التسلسل الهرمي لعرض النشاط
كي يتمكّن تطبيقك من الاستماع إلى تغييرات الضبط.
1. إدخال السمة configChanges
عدِّل العنصر <activity> في بيان التطبيق عن طريق إضافة قيم
keyboard|keyboardHidden إلى قائمة
تغييرات الإعدادات المُدارة سابقًا:
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-02-06 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-02-06 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Manage detachable keyboard configuration changes\n\n\u003cbr /\u003e\n\nThe Android system triggers a configuration change every time a keyboard is\nattached to or detached from a device. To ensure a seamless user experience and\nmaximize user productivity on large screen devices with detachable keyboards,\nyour app needs to effectively manage keyboard configuration changes.\n\nPrevent activity recreation on keyboard change\n----------------------------------------------\n\nTo prevent your activity from being recreated when a detachable keyboard is\nattached or detached, add keyboard-related values to the `configChanges`\nattribute of your app manifest and add a view to the activity's view hierarchy\nso your app can listen for configuration changes.\n\n### 1. Declare the `configChanges` attribute\n\nUpdate the `\u003cactivity\u003e` element in the app manifest by adding the\n`keyboard|keyboardHidden` values to the list of already managed configuration\nchanges: \n\n \u003cactivity\n ...\n android:configChanges=\"...|keyboard|keyboardHidden\"\u003e\n\n### 2. Add an empty view to the view hierarchy\n\nDeclare a new view and add your handler code inside the view's\n`onConfigurationChanged()` method: \n\n### Kotlin\n\n```kotlin\nval v = object : View(this) {\n override fun onConfigurationChanged(newConfig: Configuration?) {\n super.onConfigurationChanged(newConfig)\n // Handler code here.\n }\n}\n```\n\n### Java\n\n```java\nView v = new View(this) {\n @Override\n protected void onConfigurationChanged(Configuration newConfig) {\n super.onConfigurationChanged(newConfig);\n // Handler code here.\n }\n};\n```\n| **Note:** Compose-based hierarchies require the addition of a view because the view's configuration handler is the only method that is always called for configuration changes.\n\nKey points\n----------\n\n- [`android:configChanges`](/guide/topics/manifest/activity-element#config): Attribute of the app manifest's `\u003cactivity\u003e` element. Informs the system about configuration changes the app manages.\n- [`View#onConfigurationChanged()`](/develop/ui/compose/quick-guides/content/(/reference/kotlin/android/view/View#onconfigurationchanged)) : Method that reacts to propagation of a new app configuration.\n\nResults\n-------\n\nYour app now responds to an external keyboard being attached or detached\nwithout recreating the running activity.\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Optimize for large screens\n\nEnable your app to support an optimized user experience on tablets, foldables, and ChromeOS devices. \n[Quick guide collection](/quick-guides/collections/optimize-for-large-screens) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]