自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

鴻蒙Harmony應(yīng)用開發(fā)view-binding插件,和findComponentById說再見

開發(fā)
文章由鴻蒙社區(qū)產(chǎn)出,想要了解更多內(nèi)容請(qǐng)前往:51CTO和華為官方戰(zhàn)略合作共建的鴻蒙技術(shù)社區(qū)https://harmonyos.51cto.com/#zz

[[374602]]

想了解更多內(nèi)容,請(qǐng)?jiān)L問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

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

harmony-view-binding

最新版本:Gitee倉庫查看

是什么?

- view-binding for harmony

- 鴻蒙應(yīng)用開發(fā)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. 執(zhí)行g(shù)radle sync 即可自動(dòng)生成ViewBinding類,生成目錄在feature中的build/generated/source/viewBinding中,

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

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

主要是兩個(gè)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.  

 可選項(xiàng)

1. 提供設(shè)置根布局api

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

2. 支持feature模塊view-binding功能的開啟與關(guān)閉:

feature中的build.gradle中設(shè)置

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

 3. 支持針對(duì)單個(gè)xml布局文件開啟與關(guān)閉view-binding功能

默認(rèn)是都開啟,如需關(guān)閉,需在xml根節(jié)點(diǎn)中加入如下信息:

  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

©著作權(quán)歸作者和HarmonyOS技術(shù)社區(qū)共同所有,如需轉(zhuǎn)載,請(qǐng)注明出處,否則將追究法律責(zé)任.

想了解更多內(nèi)容,請(qǐng)?jiān)L問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

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

 

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

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開發(fā)

2013-09-16 09:25:55

PureDiscoveDave Copp搜索

2013-08-13 14:22:33

開發(fā)者微軟Windows Pho

2020-04-06 16:52:01

else關(guān)鍵字編程語言

2024-05-31 08:32:17

2013-07-12 09:28:44

2017-09-12 14:00:10

機(jī)器學(xué)習(xí)深度學(xué)習(xí)人工智能

2019-10-10 10:30:26

MVCModelController

2015-07-20 10:51:09

Win10照片DNA云服務(wù)

2020-12-29 10:36:34

互聯(lián)網(wǎng)數(shù)據(jù)技術(shù)

2013-12-20 09:59:34

小米閃購模式雷軍

2014-07-14 11:47:03

火狐瀏覽器

2023-02-23 19:24:47

2023-02-26 00:17:45

2023-09-02 22:02:58

TCP協(xié)議四次揮手

2018-04-08 09:33:58

2013-03-19 11:28:01

Windows 7 R
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)