Stay organized with collections
Save and categorize content based on your preferences.
public
interface
TransformationMethod
android.text.method.TransformationMethod
|
Known indirect subclasses
|
TextView uses TransformationMethods to do things like replacing the
characters of passwords with dots, or keeping the newline characters
from causing line breaks in single-line text fields.
Summary
Public methods |
abstract
CharSequence
|
getTransformation(CharSequence source, View view)
Returns a CharSequence that is a transformation of the source text --
for example, replacing each character with a dot in a password field.
|
abstract
void
|
onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction, Rect previouslyFocusedRect)
This method is called when the TextView that uses this
TransformationMethod gains or loses focus.
|
Public methods
public abstract CharSequence getTransformation (CharSequence source,
View view)
Returns a CharSequence that is a transformation of the source text --
for example, replacing each character with a dot in a password field.
Beware that the returned text must be exactly the same length as
the source text, and that if the source text is Editable, the returned
text must mirror it dynamically instead of doing a one-time copy.
The method should not return null
unless source
is null
.
Parameters |
source |
CharSequence |
view |
View |
onFocusChanged
public abstract void onFocusChanged (View view,
CharSequence sourceText,
boolean focused,
int direction,
Rect previouslyFocusedRect)
This method is called when the TextView that uses this
TransformationMethod gains or loses focus.
Parameters |
view |
View |
sourceText |
CharSequence |
focused |
boolean |
direction |
int |
previouslyFocusedRect |
Rect |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# TransformationMethod\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \n\nTransformationMethod\n====================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/text/method/TransformationMethod \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\n\n\ninterface\nTransformationMethod\n`\n\n\n`\n\n\n`\n\n|------------------------------------------|\n| android.text.method.TransformationMethod |\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [HideReturnsTransformationMethod](/reference/android/text/method/HideReturnsTransformationMethod), [PasswordTransformationMethod](/reference/android/text/method/PasswordTransformationMethod), [ReplacementTransformationMethod](/reference/android/text/method/ReplacementTransformationMethod), [SingleLineTransformationMethod](/reference/android/text/method/SingleLineTransformationMethod) |---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [HideReturnsTransformationMethod](/reference/android/text/method/HideReturnsTransformationMethod) | This transformation method causes any carriage return characters (\\\\r) to be hidden by displaying them as zero-width non-breaking space characters (\\\\ufeff). | | [PasswordTransformationMethod](/reference/android/text/method/PasswordTransformationMethod) | | | [ReplacementTransformationMethod](/reference/android/text/method/ReplacementTransformationMethod) | This transformation method causes the characters in the [getOriginal()](/reference/android/text/method/ReplacementTransformationMethod#getOriginal()) array to be replaced by the corresponding characters in the [getReplacement()](/reference/android/text/method/ReplacementTransformationMethod#getReplacement()) array. | | [SingleLineTransformationMethod](/reference/android/text/method/SingleLineTransformationMethod) | This transformation method causes any newline characters (\\\\n) to be displayed as spaces instead of causing line breaks, and causes carriage return characters (\\\\r) to have no appearance. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nTextView uses TransformationMethods to do things like replacing the\ncharacters of passwords with dots, or keeping the newline characters\nfrom causing line breaks in single-line text fields.\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract `[CharSequence](/reference/java/lang/CharSequence) | ` `[getTransformation](/reference/android/text/method/TransformationMethod#getTransformation(java.lang.CharSequence,%20android.view.View))`(`[CharSequence](/reference/java/lang/CharSequence)` source, `[View](/reference/android/view/View)` view) ` Returns a CharSequence that is a transformation of the source text -- for example, replacing each character with a dot in a password field. |\n| ` abstract void` | ` `[onFocusChanged](/reference/android/text/method/TransformationMethod#onFocusChanged(android.view.View,%20java.lang.CharSequence,%20boolean,%20int,%20android.graphics.Rect))`(`[View](/reference/android/view/View)` view, `[CharSequence](/reference/java/lang/CharSequence)` sourceText, boolean focused, int direction, `[Rect](/reference/android/graphics/Rect)` previouslyFocusedRect) ` This method is called when the TextView that uses this TransformationMethod gains or loses focus. |\n\nPublic methods\n--------------\n\n### getTransformation\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract CharSequence getTransformation (CharSequence source, \n View view)\n```\n\nReturns a CharSequence that is a transformation of the source text --\nfor example, replacing each character with a dot in a password field.\nBeware that the returned text must be exactly the same length as\nthe source text, and that if the source text is Editable, the returned\ntext must mirror it dynamically instead of doing a one-time copy.\nThe method should not return `null` unless `source`\nis `null`.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|-----------------------|\n| `source` | `CharSequence` \u003cbr /\u003e |\n| `view` | `View` \u003cbr /\u003e |\n\n| Returns ||\n|---------------------------------------------------|--------|\n| [CharSequence](/reference/java/lang/CharSequence) | \u003cbr /\u003e |\n\n### onFocusChanged\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onFocusChanged (View view, \n CharSequence sourceText, \n boolean focused, \n int direction, \n Rect previouslyFocusedRect)\n```\n\nThis method is called when the TextView that uses this\nTransformationMethod gains or loses focus.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-------------------------|-----------------------|\n| `view` | `View` \u003cbr /\u003e |\n| `sourceText` | `CharSequence` \u003cbr /\u003e |\n| `focused` | `boolean` \u003cbr /\u003e |\n| `direction` | `int` \u003cbr /\u003e |\n| `previouslyFocusedRect` | `Rect` \u003cbr /\u003e |"]]