HarmongOS开发之Button控件讲解

HarmongOS开发之Button控件讲解

  • 为Button添加Background(针对XML对象)
    • XML内部使用
    • 代码使用

为Button添加Background(针对XML对象)

XML内部使用

<Button
	ohos:id="$+id:bottom_play_btn"
    ohos:height="50vp"
    ohos:width="50vp"
    ohos:margin="10vp"
    ohos:background_element="$graphic:ic_play"/>

代码使用

首先我们看一下官方给定的方法:
HarmongOS开发之Button控件讲解_第1张图片
在这里给定的参数是Element类,查看文档可知下面的类有
HarmongOS开发之Button控件讲解_第2张图片
其中关于 VectorElement的描述为
Provides an Element object that supports vector drawing.
You can use this class to draw vector elements to prevent image distortion after scaling.

HarmongOS开发之Button控件讲解_第3张图片
由此我们可以使用下面方法来将 xml 用来更新Background

playBtn.setBackground(new VectorElement(this,ResourceTable.Graphic_ic_pause));

你可能感兴趣的:(鸿蒙,鸿蒙,HarmongOS,java)