在 OpenHarmony(ArkTS / ArkUI) 中,“验证码换肤”通常指的是修改验证码样式(颜色、背景、字体、边框、主题等),而不是系统级换肤。下面按常见场景给你说明做法。
OpenHarmony 目前没有官方统一的“验证码组件”,一般是用 TextInput + 自定义逻辑实现。
@Entry
@Component
struct CodePage {
@State skin: string = 'light' // light / dark
build() {
Column() {
TextInput({ placeholder: '请输入验证码' })
.width('80%')
.height(50)
.backgroundColor(this.skin === 'light' ? '#FFFFFF' : '#333333')
.fontColor(this.skin === 'light' ? '#000000' : '#FFFFFF')
.border({
width: 1,
color: this.skin === 'light' ? '#CCCCCC' : '#888888'
})
Button('切换皮肤')
.onClick(() => {
this.skin = this.skin === 'light' ? 'dark' : 'light'
})
}
}
}
✅ 优点:简单、实时生效
如果是自己画的验证码:
Canvas(this.context)
.onReady(() => {
this.context.fillStyle = this.skin === 'light' ? '#000' : '#fff'
this.context.fillText('1234', 20, 40)
})
你可以把颜色抽成配置:
const theme = {
light: { text: '#000', bg: '#fff' },
dark: { text: '#fff', bg: '#000' }
}
resources 中定义resources/
├─ base/
│ ├─ element/
│ │ └─ color.json
├─ dark/
│ ├─ element/
│ │ └─ color.json
color.json
{
"color": [
{ "name": "code_text", "value": "#000000" }
]
}
使用:
.fontColor($r('app.color.code_text'))
系统切换深色模式时自动换肤。
AppStorage.setOrCreate('skin', 'dark')
组件中读取:
@StorageLink('skin') skin: string
| 项目 | 可换内容 |
|---|---|
| 背景 | 颜色 / 图片 |
| 文字 | 颜色 / 字体 |
| 边框 | 颜色 / 圆角 |
| 干扰线 | 颜色 |
| 主题 | 浅色 / 深色 |
如果你说的是 某个具体组件(如第三方验证码库 / 短信验证码 UI),可以告诉我:
我可以给你更针对性的代码。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。