Set content type
On Android, you can set a content type by using the android:autofillHints property.
The following values are defined:
creditCardExpirationDate: auto-fillcredit card expiration datecreditCardExpirationDay: credit card expiration daycreditCardExpirationMonth: credit card expiration monthcreditCardExpirationYear: credit card expiration yearcreditCardNumber: credit card numbercreditCardSecurityCode: credit card security codeemailAddress: email addressname: namepassword: passwordphone: phone numberpostalAddress: postal addresspostalCode: postal codeusername: username
Example of using autofillHints:
xml
<EditText
android:autofillHints="emailAddress" /> In Jetpack Compose, Autofill can be used to automatically fill TextField with predefined data, such as email, credit card information, etc.
You can set AutoFillType to specify which type of data should be prompted to user. The following values are defined:
AddressAuxiliaryDetails: auxiliary address detailsAddressCountry: country name/ codeAddressLocality: address locality (city/town)AddressRegion: region/ stateAddressStreet: street addressBirthDateDay: birth day(of the month)BirthDateFull: full birth dateBirthDateMonth: birth monthBirthDateYear: birth yearCreditCardExpirationDate: credit card expiration dateCreditCardExpirationDay: credit card expiration dayCreditCardExpirationMonth: credit card expiration monthCreditCardExpirationYear: credit card expiration yearCreditCardNumber: credit card numberCreditCardSecurityCode: credit card security codeEmailAddress: email addressGender: genderNewPassword:newly created password for save/updateNewUsername: newly created username for save/updatePassword: passwordPersonFirstName: person's first/ given namePersonFullName: person's full namePersonLastName: person's last/ family namePersonMiddleInitial: person's middle initialPersonMiddleName: person's middle namePersonNamePrefix: person's name prefixPersonNameSuffix: person's name suffixPhoneCountryCode: phone number's country codePhoneNumber: phone number with country codePhoneNumberDevice: device's phone number usually for Sign Up / OTP flowsPhoneNumberNational: phone number without country codePostalAddress: postal addressPostalCode: postal codePostalCodeExtended: extended ZIP/ POSTAL codeSmsOtpCode: SMS One Time Password (OTP)Username: username
kotlin
// Create custom composable with AutoFill to later wrap it with TextField
@ExperimentalComposeUiApi
@Composable
private fun Autofill(
autofillTypes: List<AutofillType>,
onFill: ((String) -> Unit),
content: @Composable BoxScope.() -> Unit
) {
val autofill = LocalAutofill.current
val autofillTree = LocalAutofillTree.current
val autofillNode =
remember(autofillTypes, onFill) {
AutofillNode(onFill = onFill, autofillTypes = autofillTypes)
}
Box(
modifier =
Modifier.onFocusChanged {
if (it.isFocused) {
autofill?.requestAutofillForNode(autofillNode)
} else {
autofill?.cancelAutofillForNode(autofillNode)
}
}
.onGloballyPositioned { autofillNode.boundingBox = it.boundsInWindow() },
content = content
)
DisposableEffect(autofillNode) {
autofillTree.children[autofillNode.id] = autofillNode
onDispose { autofillTree.children.remove(autofillNode.id) }
}
}
// AutoFill composable usage
var name by
rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) }
Autofill(
// We can pass here multiple AutofillTypes
autofillTypes = listOf(AutofillType.PersonFullName, AutofillType.PersonLastName),
onFill = { name = TextFieldValue(it) }
) {
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Name") },
)
} On iOS, you can set a content type by using the textContentType property.
The following values are defined in UITextContentType:
addressCity: entering a cityaddressCityAndState: entering a city and stateaddressState: entering a statecountryName: entering a countrycreditCardNumber: entering a credit card numberdateTime: entering a date, time, or durationemailAddress: entering an email addressfamilyName: entering a family name, or last nameflightNumber: entering an airline flight numberfullStreetAddress: entering a street address that fully identifies a locationgivenName: entering a first namejobTitle: entering a job titlelocation: entering a locationmiddleName: entering a middle namename: entering a namenamePrefix: entering a prefix or titlenameSuffix: entering a suffixnewPassword: entering a new passwordnickname: entering a nicknameoneTimeCode: entering a one-time codeorganizationName: entering an organization namepassword: entering a passwordpostalCode: entering a postal codeshipmentTrackingNumber: entering a parcel tracking numberstreetAddressLine1: entering the first line of an addressstreetAddressLine2: entering the second line of an addresssublocality: entering a sublocalitytelephoneNumber: entering a telephone numberURL: entering a URLusername: entering a username
Example of using textContentType:
swift
emailField.textContentType = .emailAddress In SwiftUI, you can set a content type by using the textContentType-ufdv) view modifier.
The following values are defined in UITextContentType:
addressCity: entering a cityaddressCityAndState: entering a city name with a state nameaddressState: entering a state namebirthdate: entering a date of birthbirthdateDay: entering the day component of a birthdatebirthdateMonth: entering the month component of a birthdatebirthdateYear: entering the year component of a birthdatecellularEID: entering an embedded identity document number for an eSIMcellularIMEI: entering an international mobile equipment identity number for an eSIMcountryName: entering a country or region namecreditCardExpiration: entering an expiration date on a credit cardcreditCardExpirationMonth: entering the month component of an expiration date on a credit cardcreditCardExpirationYear: entering the year component of an expiration date on a credit cardcreditCardFamilyName: entering a family name, or last name, on a credit cardcreditCardGivenName: entering a first name on a credit cardcreditCardMiddleName: entering a middle name on a credit cardcreditCardName: entering a name on a credit cardcreditCardNumber: entering a credit card numbercreditCardSecurityCode: entering a credit card security codecreditCardType: entering a credit card typedateTime: entering a date, time, or durationemailAddress: entering an email addressfamilyName: entering a family name, or last nameflightNumber: entering an airline flight numberfullStreetAddress: entering a street address that fully identifies a locationgivenName: entering a first namejobTitle: entering a job titlelocation: entering a location, such as a point of interest, an address, or another identifier for a locationmiddleName: entering a middle namename: entering a namenamePrefix: entering a prefix or title, such as Dr.nameSuffix: entering a suffix, such as Jr.newPassword: entering a new passwordnickname: entering a nicknameoneTimeCode: entering a one-time codeorganizationName: entering an organization namepassword: entering a passwordpostalCode: entering a postal codeshipmentTrackingNumber: entering a parcel tracking numberstreetAddressLine1: entering the first line of a street addressstreetAddressLine2: entering the second line of a street addresssublocality: entering a sublocalitytelephoneNumber: entering a telephone numberURL: entering a URLusername: entering an account or login name
Example of using textContentType:
swift
@State var emailAddress: String = ""
var body: some View {
TextField("Email", text: $emailAddress)
.textContentType(.emailAddress)
} In Flutter, you can set a content type by using the autoFillHints property.
It's important to note that constants are platform dependent and don't work the same everywhere, or even at all.
The following constants are defined:
addressCity: The input field expects an address locality (city/town).addressCityAndState: The input field expects a city name combined with a state name.addressState: The input field expects a region/state.birthday: The input field expects a person's full birth date.birthdayDay: The input field expects a person's birth day(of the month).birthdayMonth: The input field expects a person's birth month.birthdayYear: The input field expects a person's birth year.countryCode: The input field expects an ISO 3166-1-alpha-2 country code.countryName: The input field expects a country name.creditCardExpirationDate: The input field expects a credit card expiration date.creditCardExpirationDay: The input field expects a credit card expiration day.creditCardExpirationMonth: The input field expects a credit card expiration month.creditCardExpirationYear: The input field expects a credit card expiration year.creditCardFamilyName: The input field expects the holder's last/family name as given on a credit card.creditCardGivenName: The input field expects the holder's first/given name as given on a credit card.creditCardMiddleName: The input field expects the holder's middle name as given on a credit card.creditCardName: The input field expects the holder's full name as given on a credit card.creditCardNumber: The input field expects a credit card number.creditCardSecurityCode: The input field expects a credit card security code.creditCardType: The input field expects the type of a credit card, for example "Visa".email: The input field expects an email address.familyName: The input field expects a person's last/family name.fullStreetAddress: The input field expects a street address that fully identifies a location.gender: The input field expects a gender.givenName: The input field expects a person's first/given name.impp: The input field expects a URL representing an instant messaging protocol endpoint.jobTitle: The input field expects a job title.language: The input field expects the preferred language of the user.location: The input field expects a location, such as a point of interest, an address,or another way to identify a location.middleInitial: The input field expects a person's middle initial.middleName: The input field expects a person's middle name.name: The input field expects a person's full name.namePrefix: The input field expects a person's name prefix or title, such as "Dr.".nameSuffix: The input field expects a person's name suffix, such as "Jr.".newPassword: The input field expects a newly created password for save/update.newUsername: The input field expects a newly created username for save/update.nickname: The input field expects a nickname.oneTimeCode: The input field expects a SMS one-time code.organizationName: The input field expects an organization name corresponding to the person, address, or contact information in the other fields associated with this field.password: The input field expects a password.photo: The input field expects a photograph, icon, or other image corresponding to the company, person, address, or contact information in the other fields associated with this field.postalAddress: The input field expects a postal address.postalAddressExtended: The input field expects an auxiliary address details.postalAddressExtendedPostalCode: The input field expects an extended ZIP/POSTAL code.postalCode: The input field expects a postal code.streetAddressLevel1: The first administrative level in the address. This is typically the province in which the address is located. In the United States, this would be the state. In Switzerland, the canton. In the United Kingdom, the post town.streetAddressLevel2: The second administrative level, in addresses with at least two of them. In countries with two administrative levels, this would typically be the city, town, village, or other locality in which the address is located.streetAddressLevel3: The third administrative level, in addresses with at least three administrative levels.streetAddressLevel4: The finest-grained administrative level, in addresses which have four levels.streetAddressLine1: The input field expects the first line of a street address.streetAddressLine2: The input field expects the second line of a street address.streetAddressLine3: The input field expects the third line of a street address.sublocality: The input field expects a sublocality.telephoneNumber: The input field expects a telephone number.telephoneNumberAreaCode: The input field expects a phone number's area code, with a country -internal prefix applied if applicable.telephoneNumberCountryCode: The input field expects a phone number's country code.telephoneNumberDevice: The input field expects the current device's phone number, usually for Sign Up / OTP flows.telephoneNumberExtension: The input field expects a phone number's internal extension code.telephoneNumberLocal: The input field expects a phone number without the country code and area code components.telephoneNumberLocalPrefix: The input field expects the first part of the component of the telephone number that follows the area code, when that component is split into two components.telephoneNumberLocalSuffix: The input field expects the second part of the component of the telephone number that follows the area code, when that component is split into two components.telephoneNumberNational: The input field expects a phone number without country code.transactionAmount: The amount that the user would like for the transaction (e.g. when entering a bid or sale price).transactionCurrency: The currency that the user would prefer the transaction to use, in ISO 4217 currency code.url: The input field expects a URL.username: The input field expects a username or an account name.
dart
TextFormField(
autofillHints: [AutofillHints.email]
) In React Native,there are different properties for Android and iOS to set the content type. For Android, you can use the autoComplete property. For iOS, you can use the textContentType property.
Available values for autoComplete on Android:
birthdate-daybirthdate-fullbirthdate-monthbirthdate-yearcc-csccc-expcc-exp-daycc-exp-monthcc-exp-yearcc-numberemailgendernamename-familyname-givenname-middlename-middle-initialname-prefixname-suffixpasswordpassword-newpostal-addresspostal-address-countrypostal-address-extendedpostal-address-extended-postal-codepostal-address-localitypostal-address-regionpostal-codestreet-addresssms-otpteltel-country-codetel-nationaltel-deviceusernameusername-newoff
Available values for textContentType on iOS:
noneURLaddressCityaddressCityAndStateaddressStatecountryNamecreditCardNumberemailAddressfamilyNamefullStreetAddressgivenNamejobTitlelocationmiddleNamenamenamePrefixnameSuffixnicknameorganizationNamepostalCodestreetAddressLine1streetAddressLine2sublocalitytelephoneNumberusernamepasswordnewPasswordoneTimeCode
jsx
<TextInput
autoComplete='email'
textContentType='emailAddress'
/> In MAUI, there is no built-in way to create a custom action, but you can achieve this via Platform Behavior. See the code for an example of usage.
PlatformBehavior
csharp
public class InputContentTypeBehavior
#if IOS
: PlatformBehavior<Entry, UIKit.UITextField>
#elif ANDROID
: PlatformBehavior<Entry, Android.Widget.EditText>
#endif
{
public static readonly BindableProperty FieldTypeAndroidProperty =
BindableProperty.Create(
nameof(FieldTypeAndroid),
typeof(FieldTypeAndroid),
typeof(AccessibilityCustomActionBehavior),
FieldTypeAndroid.None
);
public FieldTypeAndroid FieldTypeAndroid
{
get => (FieldTypeAndroid)GetValue(FieldTypeAndroidProperty);
set => SetValue(FieldTypeAndroidProperty, value);
}
public static readonly BindableProperty FieldTypeiOSProperty =
BindableProperty.Create(
nameof(FieldTypeiOS),
typeof(FieldTypeiOS),
typeof(AccessibilityCustomActionBehavior),
FieldTypeiOS.None
);
public FieldTypeiOS FieldTypeiOS
{
get => (FieldTypeiOS)GetValue(FieldTypeiOSProperty);
set => SetValue(FieldTypeiOSProperty, value);
}
#if ANDROID
protected override void OnAttachedTo(Entry bindable, Android.Widget.EditText platformView)
{
base.OnAttachedTo(bindable, platformView);
if (FieldTypeAndroid != FieldTypeAndroid.None)
{
platformView.SetAutofillHints(
FirstCharToLowerCase(FieldTypeAndroid.ToString())
);
}
}
private string? FirstCharToLowerCase(string? str)
{
if (!string.IsNullOrEmpty(str) && char.IsUpper(str[0]))
return str.Length == 1 ? char.ToLower(str[0]).ToString() : char.ToLower(str[0]) + str[1..];
return str;
}
#elif IOS
protected override void OnAttachedTo(Entry bindable, UIKit.UITextField platformView)
{
base.OnAttachedTo(bindable, platformView);
var textType = GetiOSFieldType(FieldTypeiOS);
platformView.TextContentType = textType;
}
private Foundation.NSString GetiOSFieldType(FieldTypeiOS fieldType)
{
try
{
var propertyInfo = typeof(UIKit.UITextContentType)
.GetProperty(
fieldType.ToString(),
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static
);
return (Foundation.NSString)propertyInfo.GetValue(null, null);
}
catch { }
return Foundation.NSString.Empty;
}
#endif
}
public enum FieldTypeAndroid
{
None,
CreditCardExpirationDate,
CreditCardExpirationDay,
CreditCardExpirationMonth,
CreditCardExpirationYear,
CreditCardNumber,
CreditCardSecurityCode,
EmailAddress,
Name,
Password,
Phone,
PostalAddress,
PostalCode,
Username
}
public enum FieldTypeiOS
{
None,
AddressCity,
AddressCityAndState,
AddressState,
CountryName,
CreditCardNumber,
EmailAddress,
FullStreetAddress,
GivenName,
JobTitle,
Location,
MiddleName,
Name,
NamePrefix,
NameSuffix,
NewPassword,
Nickname,
OneTimeCode,
OrganizationName,
Password,
PostalCode,
StreetAddressLine1,
StreetAddressLine2,
Sublocality,
TelephoneNumber,
Url,
Username
} xml
<Entry>
<Entry.Behaviors>
<local:InputContentTypeBehavior FieldTypeAndroid="EmailAddress" FieldTypeiOS="NewPassword" />
</Entry.Behaviors>
</Entry> csharp
var entry = new Entry();
entry.Behaviors.Add(new InputContentTypeBehavior
{
FieldTypeAndroid = FieldTypeAndroid.CreditCardExpirationDate,
FieldTypeiOS = FieldTypeiOS.AddressCity
}); Xamarin.Forms does not support content types for input fields. You can create your own autofill effect. Unfortunately, the pull request for adding it to XamarinCommunitToolkit has been closed.
csharp
Not available, contribute! Set keyboard type
On Android, you can set a keyboard type by using the android:inputType property. You can combine values with each other.
The following constants are defined:
date: for entering a datedatetime: for entering a date and timenone: to disable inputnumber: for entering a numbernumberDecimal: for entering decimal numbersnumberPassword: for entering a numeric passwordnumberSigned: for entering a positive or negative numberphone: for entering a telephone numbertext: for entering normal texttextAutoComplete: to enable automatic completiontextAutoCorrect: to enable automatic correctiontextCapCharacters: to automatically convert characters to uppercasetextCapSentences: to automatically capitalize sentencestextCapWords: to automatically capitalize wordstextEmailAddress: for entering an email addresstextEmailSubject: for entering the subject of an emailtextFilter: for entering text to filter withtextImeMultiLine: to force entering multiple lines of texttextLongMessage: for entering a long messagetextMultiLine: for entering multiple lines of texttextNoSuggestions: to disable suggestionstextPassword: for entering a passwordtextPersonName: for entering a nametextPhonetic: for entering phonetic texttextPostalAddress: for entering a postal addresstextShortMessage: for entering a short messagetextUri: for entering a URLtextVisiblePassword: for entering a visible passwordtextWebEditText: for entering text in a web formtextWebEmailAddress: for entering an email address in a web formtextWebPassword: for entering a password in a web formtime: for entering a time
Example of using inputType:
xml
<EditText
android:inputType="text|textMultiLine|textCapSentences" /> In Jetpack Compose, you can set a keyboard type by using the KeyboardType class in keyboardOptions property of TextField).
The following constants are defined for KeyboardType:
Ascii): for entering ASCII charactersDecimal): for entering decimalsEmail): for entering email addressesNumber): for entering digitsNumberPassword): for entering number passwordPassword): for entering passwordPhone): for entering phone numbersText): for entering regular textUnspecified): default keyboard typeUri): for entering URIs
Example of using KeyboardType:
kotlin
TextField(
value = "",
onValueChange = { /* State update logic */ },
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number)
) On iOS, you can set a keyboard type by using the keyboardType property.
The following types are defined:
asciiCapable: a keyboard that displays standard ASCII charactersasciiCapableNumberPad: a number pad that outputs only ASCII digitsdecimalPad: a keyboard with numbers and a decimal pointdefault: the default keyboardemailAddress: a keyboard for entering email addressesnamePhonePad: a keypad for entering a person’s name or phone numbernumberPad: a numeric keypad for PIN entrynumbersAndPunctuation: a keyboard for numbers and punctuationphonePad: a keypad for entering telephone numbersURL: a keyboard for URL entrytwitter: a keyboard for Twitter text entry, with easy access to the at '@' and hash '#' characterswebSearch: a keyboard for web search terms and URL entry
Example of using keyboardType:
swift
usernameField.keyboardType = .numberPad In SwiftUI, you can set a keyboard type by using the keyboardType) view modifier.
The following types are defined:
asciiCapable: a keyboard that displays standard ASCII charactersasciiCapableNumberPad: a number pad that outputs only ASCII digitsdecimalPad: a keyboard with numbers and a decimal pointdefault: the default keyboardemailAddress: a keyboard for entering email addressesnamePhonePad: a keypad for entering a person’s name or phone numbernumberPad: a numeric keypad for PIN entrynumbersAndPunctuation: a keyboard for numbers and punctuationphonePad: a keypad for entering telephone numbersURL: a keyboard for URL entrytwitter: a keyboard for Twitter text entry, with easy access to the at '@' and hash '#' characterswebSearch: a keyboard for web search terms and URL entry
Example of using keyboardType:
swift
@State private var phoneNumber: String = ""
var body: some View {
TextField("Phone Number", text: $phoneNumber)
// Set keyboard type
.keyboardType(.numberPad)
} In Flutter, you can set a keyboard type by using the keyboardType property.
The following values are defined in TextInputType:
datetime: Keyboard optimized for entering date and time, iOS displays default keyboard.emailAddress: Keyboard optimized for entering e-mail addresses.multiline: Optimized for multiline text input, by having an enter key.name: Keyboard optimized for inputting a person's namenone: Prevents the OS from displaying a keyboard.number: Optimized for unsigned numerical input.phone: Number keyboard with '*' and '#'.streetAddress: Optimized for entering addresses, iOS displays default keyboard.text: Optimized for text input.url: Optimized keyboard for entering URLs with '/' and '.'.visiblePassword: Keyboard with letters and numbers.
Example of using keyboardType:
dart
TextField(
keyboardType: TextInputType.emailAddress,
) In React Native, you can set a keyboard type by using the keyboardType property.
The following values work across platforms:
defaultnumber-paddecimal-padnumericemail-addressphone-padurl
The following values work on iOS only:
ascii-capablenumbers-and-punctuationname-phone-padtwitterweb-search
The following values work on Android only:
visible-password
jsx
<TextInput keyboardType="email-address" /> In Xamarin.Forms, you can set a keyboard type by using the Keyboard property.
The following Keyboard properties are defined:
Chat: keyboard for chatting, includesemojiDefault: default keyboardEmail: keyboard for entering an e-mail, includes@Numeric: keyboard for entering numbers, includes,and.Plain: keyboard for entering plain textTelephone: keyboard for entering phone numbers, includesplusandhashText: keyboard for entering text, includesenterUrl: keyboard for entering url's, includes/
xml
<Editor Keyboard="Email" />