Preview 2.0 is now in Public Beta!
Read the Announcement
Note: You are on the beta version of our docs. This is a work in progress and may contain broken links and pages.

<TextView> is a UI component that shows an editable or a read-only multi-line text container. You can use it to let users type large text in your app or to show longer, multi-line text on the screen.

<TextView> extends TextBase and EditableTextBase which provide additional properties and events.


xml
<TextView
  loaded="onTextViewLoaded"
  hint="Enter Date"
  text="{{ viewDate }}"
  secure="false"
  keyboardType="datetime"
  returnKeyType="done"
  autocorrect="false"
  maxLength="10"
/>
ts
import { Observable, Page, TextView } from '@nativescript/core'

export function onNavigatingTo(args) {
  const page = args.object as Page
  const vm = new Observable()
  vm.set('viewDate', '')
  page.bindingContext = vm
}
export function onTextViewLoaded(argsloaded) {
  const textView = argsloaded.object as TextView
  textView.on('focus', (args) => {
    const view = args.object as TextView
    console.log('On TextView focus')
  })
  textView.on('blur', (args) => {
    const view = args.object as TextView
    console.log('On TextView blur')
  })
}

Displaying multi-style text

To apply multiple styles to the text in your <TextView>, you can use <FormattedString>

xml
<TextView editable="false">
  <FormattedString>
    <span text="You can use text attributes such as " />
    <span text="bold, " fontWeight="Bold" />
    <span text="italic " fontStyle="Italic" />
    <span text="and " />
    <span text="underline." textDecoration="Underline" />
  </FormattedString>
</TextView>

Props

text

xml
<TextView text="{{ viewDate }}" />
ts
text: string = textView.text

Gets or sets the text value of the component.


hint

xml
<TextView hint="hint" />
ts
hint: string = textView.hint

Gets or sets the placeholder text for the component.


editable

xml
<TextView editable="false" />
ts
editable: boolean = textView.editable
//or
textView.editable = false

Toggles the ability to take user input.


keyboardType

xml
<TextView keyboardType="number" />
ts
textView.keyboardType = CoreTypes.KeyboardType.number
//or
keyboardType: CoreTypes.KeyboardType = textView.keyboardType

Shows the appropriate keyboard keys for the data the TextField will capture. See CoreTypes.KeyboardType for available values.


returnKeyType

xml
<TextView returnKeyType="next" />
ts
textView.returnKeyType = CoreTypes.ReturnKeyType.next
//or
returnKeyType: CoreTypes.ReturnKeyType = textView.returnKeyType

Gets or sets the label of the return key. See CoreTypes.ReturnKeyType for available values.


maxLines

xml
<TextView maxLines="2" />
ts
textView.maxLines = 2

Limits input to a certain number of lines.


autocorrect

xml
<TextView returnKeyType="autocorrect" />
ts
textView.autocorrect = true
//or
autocorrect: boolean = textView.autocorrect

Enables or disables autocorrect.


...Inherited

For additional inherited properties not shown, refer to the API Reference.


Events

NameDescription
textChangeEmitted when the text changes. Event data type: PropertyChangeData
returnPressEmitted when the return key is pressed. Event data type: EventData
focusEmitted when the field is in focus. Event data type: EventData
blurEmitted when the field loses focus. Event data type: EventData

Native component

AndroidiOS
android.widget.EditTextUITextView
Previous
TextField