HarmonyOS应用开发基础
点击事件的四种写法
首先在ability_main.xml中添加一个Button和Text<Button ohos:id="$+id:but1" ohos:height="match_content" ohos:width="match_content" ohos:text="点我" ohos:text_size="200" ohos:background_element="red" /> <Text ohos:height="match_content" ohos:width="match_content" ohos:id="$+id:text1" ohos:text="text" ohos:text_size="100" />
第一种方法:定义实现类
首先我们需要去找到我们之前已经定义的button和Text,通过id查到
在最外层定义全局变量text1
Text text1=null;
//1.找到按钮和文本框
Button but1=(Button)findComponentById(ResourceTable.Id_but1);
text1=(Text)f