Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Composeでの自動入力(作成:GPT-4o)

Android Composeでの自動入力(作成:GPT-4o)

tonionagauzzi

April 24, 2025
Tweet

More Decks by tonionagauzzi

Other Decks in Programming

Transcript

  1. Jetpack Composeでの自動入力 Compose UIを1.8.0以降にアップデート Modifier.semantics を使用して contentType を指定 Column {

    TextField( value = username.value, onValueChange = {username.value = it}, modifier = Modifier.semantics { contentType = ContentType.Username } ) TextField( value = password.value, onValueChange = {password.value = it}, modifier = Modifier.semantics { contentType = ContentType.Password } ) } 3
  2. 解決策 CredentialManager を使用 androidx.credentials をインポート Column { val context =

    LocalContext.current val coroutineScope = rememberCoroutineScope() TextField( value = newPassword.value, onValueChange = { newPassword.value = it }, modifier = Modifier.semantics { contentType = ContentType.NewPassword }, ) Button(onClick = { try { coroutineScope.launch { val credentialManager = CredentialManager.create(context) val request = CreatePasswordRequest(username, newPassword.value) credentialManager.createCredential( request = request, context = context, ) } } catch (e: CreateCredentialException) { 5