如何在Google Card Service中实现密码输入框功能?
在Google Card Service中实现密码类型输入框
Google Card Service的TextInput组件原生支持密码输入功能,只需调用其setPasswordInput(true)方法,即可将输入框设置为密码类型,输入内容会自动以星号(*)隐藏。
示例代码
function buildPasswordFormCard() { // 创建卡片构建器 const cardBuilder = CardService.newCardBuilder(); // 创建密码输入框组件 const passwordInput = CardService.newTextInput() .setFieldName("user_password") // 设置字段名,用于后续获取输入值 .setTitle("密码") // 输入框标题 .setPasswordInput(true); // 启用密码隐藏模式 // 将输入框添加到卡片分区 const cardSection = CardService.newCardSection().addWidget(passwordInput); cardBuilder.addSection(cardSection); return cardBuilder.build(); }
调用上述函数生成的卡片中,密码输入框会自动隐藏输入内容,达到你期望的星号掩码效果。
内容的提问来源于stack exchange,提问作者Poojan3037
相关产品推荐
相关产品推荐

