首页 > 编程知识 正文

鸿蒙 桌面小组件,鸿蒙系统小插件怎么添加

时间:2023-05-04 19:27:07 阅读:57295 作者:1009

机械臂

本文介绍了Picker组件在鸿蒙应用中的基本用法。

增加Picker组件

将Picker组件添加到布局中,如以下代码的第46行到第56行所示。

? XML版本=' 1.0 '编码=' utf-8 '? directionallayoutxmlns 3360 ohos=' http://schemas.Huawei.com/RES/ohos ' ohos : height=' match _ parent ' ohos : width=' match _ parent ' ohos 3360 orientation=' vertical ' component directionallayoutxmlns 3360 ohos=' http://schemas.Huawei.com/RES/ohos ' ohos : height=' match _ content ' ohos : width=' match _ content ' ohos 3360 layout _ alignment=' center ' OS 3360 height=' match _ content ' ohos 3360 layout _ align mming veco '/textfieldohos : id=' $ id : text _ field ' ohos : width=' match _ parent ' ohos 3360 height=' 30vp ' ohos 3360 text ext ] button.' ohos : background _ element=' $ graphic : background _ text _ field '/uttonohos : id=' $ id : hello _ button ' ohos : width=' match _ content ' ohos 3360 height=' match _ content ' ohohos und _ element=' $ graphic 3360 background _ button ' ohos 3360 marros OS : left _ padding=' 8vp '/pickerohos : id=' $ id : test _ picker ' ohos : height=' match _ content ' ohos 3360 width=' 300 VP ' ohos 3360 min 60 element='# E1 ffff ' ohos : layout _ alignment=' horizontal _ center ' ohos 3360 normal _ text _ size=' 16fp ' ohos 3360 selected dirize s : weight='5' ohos : width=' match _ parent '//direction ent

获取Picker组件设定和取得表示信息

获取PIcker组件后,请设置显示信息,并使用行为响应代码将最新的显示信息设置为TextField组件,如以下代码的第30行和第36行所示。

package com.example.hello harmony.slice; import com.example.hello harmony.resource table; importo hos.AAF wk.ability.ability slice; importo hos.AAF wk.content.intent; importo hos.AGP.com ponents.button; importo hos.AGP.com ponents.com ponent; importo hos.AGP.com ponents.picker; importo hos.AGP.com ponents.textfield; importo hos.AGP.utils.layout alignment; importo hos.AGP.window.dialog.toast dialog; publicclasscomponentabilitysliceextendsabilityslice { @ overridepublicvoidonstart (即时) super.onstart )即时支持获取textfield输入组件TextField tf=(TextField ) findcomponentbyid (资源表. id _ text _ field ); 获取button组件Button button=(Button ) findcomponentbyid (resource table.id _ hello _ button ); //在按钮的设定中使用button.setclickedlistener (new component.clicked listener ) (publicvoidonclick ) component v (newtoastdialog ) ); picker组件获取Picker picker=(Picker ) findcomponentbyid (resource table.id _ test _ picker ); //设置显示字符picker.setdisplayeddata (新字符串) (mon )、(Tue )、(Wed )、(Thu )、(Fri )、(Sat )、(sun ) ); //事件响应picker.setvaluechangedlistener ((picker 1,oldVal,newVal )-{TF.settext ) picker1.getdisplayeddata ) } @Override public void onActive () { super.onActive ); } @ overridepublicvoidonforeground (intent intent ) (super.onforeground ) intent ); }画面显示如下。

参考文档

Picker类:

3359 developer.harmony OS.com/cn/docs/documentation/doc-references/picker-0000010541976

Picker组件:

3359 developer.harmony OS.com/cn/docs/doc-guides/ui-Java-component-picker-000010598079000

新书介绍

《实战Python设计模式》是作者最近出版的新书。 请多关照!

本文档提供了一个可以使用Python标准GUI工具包tkinter执行23种设计模式的示例。 由此,能够使读者理解实际软件开发工作中的每个设计模式的运用场景和想要解决的问题; 另一方面,通过说明这些问题的解决过程,让读者了解在编写代码时如何判断使用设计模式的利弊,如何合理运用设计模式。

对设计模式感兴趣并想一起学习的读者,可以在本书中快速跨越从理解到运用的门槛。如果想学习Python GUI编程,可以将本书的例子作为设计和开发的参考; 使用Python语言进行图像分析、数据处理的读者可以直接根据本书的例子,迅速构建自己的系统体系结构。

你认为正文有用吗? 请分享给更多的人。

关注微信公众号【面向对象思维】轻松学习每天!

面向对象开发,面向对象思维!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。