उपयोगकर्ता के टॉगल के आधार पर पासवर्ड दिखाना या छिपाना
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
उपयोगकर्ता के टॉगल के आधार पर, पासवर्ड को छिपाने या दिखाने के लिए आइकॉन बनाया जा सकता है. इससे सुरक्षा को बेहतर बनाने के साथ-साथ, उपयोगकर्ता अनुभव को भी बेहतर बनाया जा सकता है.
वर्शन के साथ काम करना
इसे लागू करने के लिए, ज़रूरी है कि आपके प्रोजेक्ट का minSDK एपीआई लेवल 21 या उससे ज़्यादा पर सेट हो.
डिपेंडेंसी
उपयोगकर्ता के टॉगल के आधार पर पासवर्ड दिखाना या छिपाना
उपयोगकर्ता के टॉगल के आधार पर पासवर्ड दिखाने या छिपाने के लिए, जानकारी डालने के लिए एक इनपुट फ़ील्ड बनाएं और टॉगल के लिए क्लिक किए जा सकने वाले आइकॉन का इस्तेमाल करें:
इसमें क्लिक किया जा सकने वाला आइकॉन होता है, जो showPassword की वैल्यू को टॉगल करता है.
showPassword की स्थिति के हिसाब से, textObfuscationMode एट्रिब्यूट और ट्रेलिंग आइकॉन के दिखने/न दिखने की स्थिति तय करता है.
नतीजे
पहली इमेज. पासवर्ड दिखाने और छिपाने वाले आइकॉन को टॉगल करना.
ऐसे संग्रह जिनमें यह गाइड शामिल है
यह गाइड, चुने गए क्विक गाइड के कलेक्शन का हिस्सा है. इसमें Android डेवलपमेंट के बड़े लक्ष्यों के बारे में बताया गया है:
डिसप्ले टेक्स्ट
टेक्स्ट, किसी भी यूज़र इंटरफ़ेस (यूआई) का मुख्य हिस्सा होता है. जानें कि उपयोगकर्ता को बेहतर अनुभव देने के लिए, ऐप्लिकेशन में टेक्स्ट को कैसे दिखाया जा सकता है.
जानें कि उपयोगकर्ता आपके ऐप्लिकेशन के साथ कैसे इंटरैक्ट कर सकते हैं. इसके लिए, टेक्स्ट डालने और इनपुट के अन्य तरीकों का इस्तेमाल करने की सुविधा लागू करें.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, Oracle और/या इससे जुड़ी हुई कंपनियों के ट्रेडमार्क या रजिस्टर किए हुए ट्रेडमार्क हैं.
आखिरी बार 2025-02-06 (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-02-06 (UTC) को अपडेट किया गया."],[],[],null,["\u003cbr /\u003e\n\nYou can create an icon to hide or show a password based on a user toggle to\nimprove security and enhance the user experience.\n\nVersion compatibility\n\nThis implementation requires that your project minSDK be set to API level 21 or\nhigher.\n\nDependencies\n\nShow or hide a password based on user toggle\n\nTo show or hide a password based on a user toggle, create an input field for\nentering information and use a clickable icon for the toggle:\n\n\n```kotlin\n@Composable\nfun PasswordTextField() {\n val state = remember { TextFieldState() }\n var showPassword by remember { mutableStateOf(false) }\n BasicSecureTextField(\n state = state,\n textObfuscationMode =\n if (showPassword) {\n TextObfuscationMode.Visible\n } else {\n TextObfuscationMode.RevealLastTyped\n },\n modifier = Modifier\n .fillMaxWidth()\n .padding(6.dp)\n .border(1.dp, Color.LightGray, RoundedCornerShape(6.dp))\n .padding(6.dp),\n decorator = { innerTextField -\u003e\n Box(modifier = Modifier.fillMaxWidth()) {\n Box(\n modifier = Modifier\n .align(Alignment.CenterStart)\n .padding(start = 16.dp, end = 48.dp)\n ) {\n innerTextField()\n }\n Icon(\n if (showPassword) {\n Icons.Filled.Visibility\n } else {\n Icons.Filled.VisibilityOff\n },\n contentDescription = \"Toggle password visibility\",\n modifier = Modifier\n .align(Alignment.CenterEnd)\n .requiredSize(48.dp).padding(16.dp)\n .clickable { showPassword = !showPassword }\n )\n }\n }\n )\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/text/TextSnippets.kt#L868-L909\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- Maintains the password visibility state in`showPassword`.\n- Uses a [`BasicSecureTextField`](/reference/kotlin/androidx/compose/foundation/text/package-summary#BasicSecureTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.text.input.TextObfuscationMode,kotlin.Char)) composable for password entry.\n- Has a clickable trailing icon, which toggles the value of `showPassword`.\n- Defines the [`textObfuscationMode`](/reference/kotlin/androidx/compose/foundation/text/input/TextObfuscationMode) attribute and the visible/not-visible state of the trailing icon by the state of `showPassword`.\n\nResults\n\n\u003cbr /\u003e\n\n**Figure 1.** Toggling the show-and-hide password icon.\n\n\u003cbr /\u003e\n\nCollections that contain this guide\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\nDisplay text \nText is a central piece of any UI. Find out different ways you can present text in your app to provide a delightful user experience. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-text) \n\nRequest user input \nLearn how to implement ways for users to interact with your app by entering text and using other means of input. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/request-user-input) \n\nHave questions or feedback \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)"]]