成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

鴻蒙Harmony應用開發view-binding插件,和findComponentById說再見

開發
文章由鴻蒙社區產出,想要了解更多內容請前往:51CTO和華為官方戰略合作共建的鴻蒙技術社區https://harmonyos.51cto.com/#zz

[[374602]]

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com/#zz

harmony-view-binding

最新版本:Gitee倉庫查看

是什么?

- view-binding for harmony

- 鴻蒙應用開發view-binding插件,消除findComponentById模版代碼

- 無注解、編譯期間生成Binding類文件

怎么用?

1. 在project根目錄的build.gradle文件中引入view-binding的maven倉庫地址和classpath

  1. buildscript { 
  2.     repositories { 
  3.         maven { 
  4.             url 'https://mirrors.huaweicloud.com/repository/maven/' 
  5.         } 
  6.         maven { 
  7.             url 'https://developer.huawei.com/repo/' 
  8.         } 
  9.  
  10.         jcenter() 
  11.         maven{ 
  12.             url 'https://dl.bintray.com/eholee/maven' 
  13.         } 
  14.     } 
  15.     dependencies { 
  16.         classpath 'com.huawei.ohos:hap:2.4.0.1' 
  17.         // view-binding 
  18.         classpath 'com.eholee.plugin:view-binding:1.0.1' 
  19.     } 

 2. 在feature模塊的build.gradle文件中引入view-binding插件

  1. apply plugin: 'com.huawei.ohos.hap' 
  2.  
  3. apply plugin: 'com.eholee.plugin.view-binding' 
  4.  
  5. ohos { 
  6.  
  7. ... 
  8.  
  9.  
  10. viewBinding{ 
  11.  
  12. enable true 
  13.  
  14.  
  15. dependencies { 
  16.  
  17. ... 
  18.  

 3. 執行gradle sync 即可自動生成ViewBinding類,生成目錄在feature中的build/generated/source/viewBinding中,

類的命名方法通過獲得xml布局文件名后遵循大駝峰法(Upper Camel Case)并追加Binding后綴,如:MainAbilityBinding

4. 在需要填充布局的地方使用

主要是兩個api:1. binding = AbilityMainBinding.parse(this); 2. binding.getRoot()

  1. public class MainAbilitySlice extends AbilitySlice { 
  2.  
  3. private AbilityMainBinding binding; 
  4.  
  5. @Override 
  6.  
  7. public void onStart(Intent intent) { 
  8.  
  9. super.onStart(intent); 
  10.  
  11. binding = AbilityMainBinding.parse(this); 
  12.  
  13. super.setUIContent(binding.getRoot()); 
  14.  
  15. binding.textHelloworld.setClickedListener(new Component.ClickedListener() { 
  16.  
  17. @Override 
  18.  
  19. public void onClick(Component component) { 
  20.  
  21. new ToastDialog(MainAbilitySlice.this).setText("click").show(); 
  22.  
  23.  
  24. }); 
  25.  
  26.  
  27. @Override 
  28.  
  29. public void onActive() { 
  30.  
  31. super.onActive(); 
  32.  
  33.  
  34. @Override 
  35.  
  36. public void onForeground(Intent intent) { 
  37.  
  38. super.onForeground(intent); 
  39.  
  40.  

 可選項

1. 提供設置根布局api

  1. parse(Context context, ComponentContainer parent, boolean attachToRoot)   

2. 支持feature模塊view-binding功能的開啟與關閉:

feature中的build.gradle中設置

  1. viewBinding{ 
  2.         enable false  
  3.         // false為關閉,插件將不會解析該feature所有的xml布局文件, 
  4.         //true為開啟,插件將會解析該feature下所有的xml布局文件 
  5. }  

 3. 支持針對單個xml布局文件開啟與關閉view-binding功能

默認是都開啟,如需關閉,需在xml根節點中加入如下信息:

  1. xmlns:eholee="http://schemas.eholee.com/viewbinding" 
  2.  eholee:view_binding="false" 
  3.  示例: 
  4.  <?xml version="1.0" encoding="utf-8"?> 
  5.  <DirectionalLayout 
  6.       xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  7.       xmlns:eholee="http://schemas.eholee.com/viewbinding" 
  8.       eholee:view_binding="false" 
  9.       ohos:height="match_parent" 
  10.       ohos:width="match_parent" 
  11.       ohos:background_element="$color:colorAppBackground" 
  12.       ohos:orientation="vertical"
  13.       ... 
  14.   </DirectionalLayout>  

 Gitee倉庫地址:https://gitee.com/jeffer_s/harmony-view-binding

參考

1. Android ViewBinding

2. com.huawei.ohos:hap:2.4.0.1 插件api

LICENSE

Apache License 2.0

©著作權歸作者和HarmonyOS技術社區共同所有,如需轉載,請注明出處,否則將追究法律責任.

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com/#zz

 

責任編輯:jianghua 來源: 鴻蒙社區
相關推薦

2009-08-01 08:46:47

2011-12-19 09:36:33

JavaJDKubuntu

2018-05-16 07:48:55

2014-03-24 09:46:32

Pythonweb開發

2013-09-16 09:25:55

PureDiscoveDave Copp搜索

2020-04-06 16:52:01

else關鍵字編程語言

2013-08-13 14:22:33

開發者微軟Windows Pho

2024-05-31 08:32:17

2013-07-12 09:28:44

2017-09-12 14:00:10

機器學習深度學習人工智能

2019-10-10 10:30:26

MVCModelController

2015-07-20 10:51:09

Win10照片DNA云服務

2020-12-29 10:36:34

互聯網數據技術

2013-12-20 09:59:34

小米閃購模式雷軍

2014-07-14 11:47:03

火狐瀏覽器

2023-02-23 19:24:47

2023-09-02 22:02:58

TCP協議四次揮手

2018-04-08 09:33:58

2023-02-26 00:17:45

2013-05-13 09:29:31

Office 365微軟Adobe
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久精品99| 欧美在线视频网 | 欧美午夜在线 | 久久国产视频网 | 蜜臀网站| 欧美a在线 | 一区日韩 | 久久久精 | 成人区一区二区三区 | 国产成人综合av | 国产精品日韩欧美一区二区三区 | 日韩精品一区二区三区高清免费 | 超碰在线播 | 激情综合五月天 | 日本一二区视频 | 午夜爽爽男女免费观看hd | 国产一级视频 | 国产高清无av久久 | 99精品久久久 | 北条麻妃一区二区三区在线视频 | 国产亚洲精品久久久久久豆腐 | 欧美一级全黄 | 国产a区| 国产一级视频在线 | 中文字幕一区在线观看视频 | 午夜无码国产理论在线 | 国内精品伊人久久久久网站 | 一区二区在线不卡 | 久久精品久久久久久 | 成人自拍视频 | 国产婷婷色综合av蜜臀av | avtt国产| 韩日一区 | 久久综合一区 | 99在线观看视频 | 色综合一区二区 | 亚洲一区在线播放 | av日日操 | 国产精品精品视频一区二区三区 | 久久91| 日本大片在线播放 |