三、修改代码
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094639.77590006357867363175714203860765:50530616014945:2800:0C50D810409C2D14A08E67C063587FE82B5AA7A180818A88491BEAE0DEBB9037.png)
如图7
打开该文件下的index.hml文件,修改代码。
- <!-- 用堆叠stack组件包裹节点div组件-->
- <stack style="background-color: #f5d354;width: 100%;height: 100%;" onclick="routerEvent">
- <!-- 右边图片(添加此段代码)-->
- <div class="right-img">
- <image class="images" src="/common/ic_default_image.png" alt="img" ></image>
- </div>
- <!-- 标题信息-->
- <div class="container">
- <div class="title_wrapper">
- <text class="title_big">
- {{ $t('strings.title_big') }}
- </text>
- <text class="title_small">
- {{ $t('strings.title_small') }}
- </text>
- </div>
- <!-- 文本信息 (修改text信息,后面加上数字标记1、2、3)-->
- <div class="list_wrapper">
- <div class="item_first">
- <image class="item_image" src='/common/ic_default.png'></image>
- <text class="item_text" onclick="routerEvent">{{ $t('strings.text') }}</text>
- </div>
- <div class="item">
- <image class="item_image" src='/common/ic_default.png'></image>
- <text class="item_text" onclick="routerEvent">{{ $t('strings.text1') }}</text>
- </div>
- <div class="item">
- <image class="item_image" src='/common/ic_default.png'></image>
- <text class="item_text" onclick="routerEvent">{{ $t('strings.text2') }}</text>
- </div>
- <div class="item">
- <image class="item_image" src='/common/ic_default.png'></image>
- <text class="item_text" onclick="routerEvent">{{ $t('strings.text3') }}</text>
- </div>
- <div class="item_last">
- <image class="item_image" src='/common/ic_default.png'></image>
- <text class="item_text" onclick="routerEvent">{{ $t('strings.text4') }}</text>
- </div>
- </div>
- </div>
- </stack>
复制代码
打开该文件下的index.css文件,修改代码(找到对应修改部分)。
- .container {
- flex-direction: column;
- justify-content: space-between;
- align-items: flex-start;
- /*注释代码*/
- /* background-color: dodgerblue;*/
- /* background-image: url('/common/ic_default_image@3x.png');*/
- /* background-repeat: no-repeat;*/
- /* background-size: cover;*/
- }
- /*添加.right-img样式*/
- .right-img{
- width: 40px;
- height: 40px;
- position: absolute;
- right: 10px;
- top: 10px;
- border-radius: 12px;
- }
- /*将.title_big中的font-size: 19px;改为16px*/
- .title_big {
- font-size: 16px;
- font-weight: bold;
- color: white;
- }
- /*适配wearable*/
- [url=home.php?mod=space&uid=205723]@MEDIA[/url] (device-type: wearable) {
- .right-img{
- display: none;
- }
- }
复制代码打开该文件下的i18n文件,打开.json文件,修改代码。
zh_CN.json:
- {
- "strings": {
- "title_big": "标题",
- "title_small": "这里是副标题",
- "text": "文本",
- "text1": "文本1",
- "text2": "文本2",
- "text3": "文本3",
- "text4": "文本4"
- }
- }
复制代码
en_US.json:
- {
- "strings": {
- "title_big": "Title",
- "title_small": "Text",
- "text": "Text",
- "text1": "Text1",
- "text2": "Text2",
- "text3": "Text3",
- "text4": "Text4"
- }
- }
复制代码1. 打开js下的default文件,打开pages文件,点击index.hml.如图8所示。
图8
修改代码:
index.hml
- <div class="container">
- <text class="title">你好,欢迎来到</text>
- <text class="title">{{title1}}</text>
- <text class="title">{{title2}}</text>
- </div>
复制代码
index.css
- .container {
- flex-direction: column;
- justify-content: center;
- align-items: center;
- width: 100%;
- height: 100%;
- }
- .title {
- font-size: 30px;
- color: #000000;
- opacity: 0.9;
- margin: 4px 0px;
- }
- @media screen and (device-type: tablet) and (orientation: landscape) {
- .title {
- font-size: 100px;
- }
- }
- @media screen and (device-type: wearable) {
- .title {
- font-size: 28px;
- color: #FFFFFF;
- }
- }
- @media screen and (device-type: tv) {
- .container {
- background-image: url("/common/images/Wallpaper.png");
- background-size: cover;
- background-repeat: no-repeat;
- background-position: center;
- }
- .title {
- font-size: 100px;
- color: #FFFFFF;
- }
- }
- @media screen and (device-type: phone) and (orientation: landscape) {
- .title {
- font-size: 60px;
- }
- }
复制代码
index.js
- export default {
- data: {
- title1: "原子化服务",
- title2: "新应用时代和新世界!"
- },
- onInit() {}
- }
复制代码四、运行效果
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094639.14792236386202287660400894686154:50530616014945:2800:C8D97B3907D6A46E8D36E1A8736A5365EA7A76C67BA04E5512733EE91D875535.png)
图9
进行登录,如图10
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094639.57048336412666951611915461497069:50530616014945:2800:3F0C8657A0CA9E3115AAAAC6577A67A2957A9C049390ADB44F7B111774F43247.png)
图10
输入你的华为账号进行登录,如图11
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094639.74633409750160278481498076631008:50530616014945:2800:CE5AE08AF5285FB482FEEC5ED6F82C8DB1DFB0DA840B1E310B2851E6E1A33B91.png)
图11
点击允许,如图12
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094639.67211519672772442267342449330346:50530616014945:2800:096028DDE75E5C805B2E36B9ECE49CDEF499E4CB1661DBA58879C30AE307F6F1.png)
图12
登陆成功,如图13,然后返回DevEco Studio。
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.37070296317624227624370262096765:50530616014945:2800:9A064AB762EA3001A6D9ED329EA5954BBC6E5F8D9CC00619B24A0ACCE53295FE.png)
图13
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.31800460106644193193545682916680:50530616014945:2800:2EDAB67F51BE2BC2EE04FB336BA7EB2DCCFA5B627C945D77AA1207420473D04E.png)
图14
开启成功,如图15。
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.56507976568012378415605834061808:50530616014945:2800:FDDA48613CEEFF90993D08AC3FB3CD6205D090D8B41B24D48B33153B47332CB5.png)
图15
点击小三角运行项目,如图16
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.66407119278843797457257234350301:50530616014945:2800:B37578D3208FE329F5E555FDF4B00755B880AB6AA3ABFDFD9DB4171224AAFE4C.png)
图16
运行成功后会出现初始化页面,如图17
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.46593831452265756806327096608285:50530616014945:2800:09CD69A1CCE87FB950CDDA276A47E66A4B0E945C38F8D2B18C11D90E095FDD9D.png)
图17
点击模拟器中的home键,回到桌面,然后从左下角或者右下角斜向上滑动,进入服务中心,如图18
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.91101427786919706723511129262623:50530616014945:2800:D09BE79AB34FA97E7014A02B7DE1C84EF4F446E13B570B1C686F745868435885.png)
图18
进入服务中心后可以看见创建的卡片(这是项目创建初始化自身就有的卡片widget),如图19
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.46325174160950939042213888413604:50530616014945:2800:585CDCABCD4DD9206E00230EC330C6B11C7E1EFDBFA4E3F538D79807377327BE.png)
图19
轻按卡片,添加至桌面,如图20
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.70325183718449422471366576400691:50530616014945:2800:99B043D827F66718CB84B1CB5B9A31E9D5315FAC2D5697A858F6D857F5A5130A.png)
图20
卡片成功添加至桌面,如图21
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.66516913802613208834771583507919:50530616014945:2800:63768095F9CCFB2598641C9CCBA8164E76B40F6E4D3074BC59F85BFE6C69235F.png)
如图21
长按桌面卡片,出现弹窗,单击更多服务卡片,选择我们之前新创建的卡片,并且添加至桌面,如图22、图23、图24
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.91769533439818779509557301583744:50530616014945:2800:200B6D5154338C606AB2687D6BCB65F518133607476BFFAECCB3CDAAEC8955F7.png)
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.91110336198641858939616265741910:50530616014945:2800:D1C57AC29D884596F779F94A3086B25D7FC816B37DB04A6AF6621397120DF40A.png)
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.29163951494910230180562053856004:50530616014945:2800:33AD9967D0C728094263025E6B63224F407CFBEB95F5F6CABE5CFAF1AA3E88D5.png)
图22 图23 图24
点击新添加至桌面的卡片,回到页面,如图25
![](https://communityfile-drcn.op.hicloud.com/FileServer/getFile/cmtybbs/421/357/287/2850086000421357287.20220617094640.03695700166178464641419306782976:50530616014945:2800:D5A4C600A18884DA5C93D9BCB3BD31F5E337CD5C18D84C0215E83A95E79DA313.png)
图 25
- 这里想显示其他模拟器效果,重复以上打开模拟器的步骤即可。
其他模拟器卡片效果可用previewr快速预览,如图26打开previewr。
图26