text | 要编辑的文本。 |
keyboardType | 键盘类型(例如,任意文本、仅数字等)。 |
autocorrection | 是否应用自动校正? |
multiline | 是否可输入多行文本? |
secure | 是否遮挡文本(密码等)? |
alert | 是否以警报模式打开键盘? |
textPlaceholder | 不存在其他文本时使用的文本。 |
characterLimit | 键盘输入字段可以输入的字符数限制。0 = 无限。(仅限 Android 和 iOS) |
在屏幕上打开操作系统提供的原生键盘。
autocorrection
确定输入是否跟踪未知单词
并向用户建议更合适的替代候选词,
然后自动替换输入的文本,除非用户明确
覆盖该操作。
multiline
确定用户是否可以输入多行
文本。
secure
标识键盘是否用于密码。除
最近键入的字符外,输入字段中的文本将向用户
隐藏。
也可以以 alert
模式打开键盘。
当键盘的输入字段中没有其他文本时,
将显示 placeholder
字符串。
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public string stringToEdit = "Hello World"; private TouchScreenKeyboard keyboard;
// Opens native keyboard void OnGUI() { stringToEdit = GUI.TextField(new Rect(10, 10, 200, 30), stringToEdit, 30);
if (GUI.Button(new Rect(10, 50, 200, 100), "Default")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default); } if (GUI.Button(new Rect(10, 150, 200, 100), "ASCIICapable")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.ASCIICapable); } if (GUI.Button(new Rect(10, 250, 200, 100), "Numbers and Punctuation")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.NumbersAndPunctuation); } if (GUI.Button(new Rect(10, 350, 200, 100), "URL")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.URL); } if (GUI.Button(new Rect(10, 450, 200, 100), "NumberPad")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.NumberPad); } if (GUI.Button(new Rect(10, 550, 200, 100), "PhonePad")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.PhonePad); } if (GUI.Button(new Rect(10, 650, 200, 100), "NamePhonePad")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.NamePhonePad); } if (GUI.Button(new Rect(10, 750, 200, 100), "EmailAddress")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.EmailAddress); } if (GUI.Button(new Rect(10, 850, 200, 100), "Social")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Social); } if (GUI.Button(new Rect(10, 950, 200, 100), "Search")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Search); } } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.