HarmonyOS 鸿蒙Next 修改textpicker选中的背景颜色
HarmonyOS 鸿蒙Next 修改textpicker选中的背景颜色 有一个需求就是要做安卓时间选择器的样式 然后我用textpicker 写一个时间选择器 但是没有找到修改选中项的背景颜色 只能改字体颜色和字号
您可以通过stack实现,demo如下
// xxx.ets
@Entry
@Component
struct TextPickerExample {
private select: number = 1
private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4']
build() {
Column() {
Stack(){
Column(){}
.width('100%')
.height(50)
.backgroundColor(Color.Green)
TextPicker({ range: this.fruits, selected: this.select })
.onChange((value: string | string[], index: number | number[]) => {
console.info('Picker item changed, value: ' + value + ', index: ' + index)
})
.disappearTextStyle({color: Color.Red, font: {size: 15, weight: FontWeight.Lighter}})
.textStyle({color: Color.Black, font: {size: 20, weight: FontWeight.Normal}})
.selectedTextStyle({color: Color.Blue, font: {size: 30, weight: FontWeight.Bolder}})
}
.width('100%')
.height('100%')
}
}
}
更多关于HarmonyOS 鸿蒙Next 修改textpicker选中的背景颜色的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
牛啊,大佬,好用,
在HarmonyOS(鸿蒙)系统中,修改TextPicker
组件选中项的背景颜色通常需要通过自定义样式或主题来实现。以下是一个简要步骤来实现这一需求:
-
定义自定义样式: 在资源文件中(如
resources/base/xml
目录下的某个.xml
文件),定义一个样式,用于指定TextPicker
的选中项背景颜色。例如:<resource> <style name="CustomTextPickerStyle"> <item name="text_picker_selected_background_color">#FF0000</item> <!-- 红色背景 --> </style> </resource>
-
应用自定义样式: 在布局文件中,为
TextPicker
组件应用上述自定义样式。例如:<TextPicker ohos:id="$+id:text_picker" ohos:width="match_parent" ohos:height="wrap_content" ohos:style="@style/CustomTextPickerStyle" />
-
检查效果: 运行应用并检查
TextPicker
组件的选中项背景颜色是否已更改为预期的颜色。
请注意,上述示例中的属性名(如text_picker_selected_background_color
)是假设性的,实际属性名可能因鸿蒙系统的版本和API而有所不同。因此,如果上述方法无效,可能需要查阅鸿蒙系统的官方文档或API参考,以找到正确的属性名。
如果问题依旧没法解决请联系官网客服,官网地址是 https://www.itying.com/category-93-b0.html