鸿蒙OS前端开发入门指南 原创

BLUESKYHOST
发布于 2021-2-12 01:04
浏览
5收藏

我将会持续更新用前端名词来记录鸿蒙api

开启沉浸式导航/隐藏状态栏

在onStart 最前面

getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS);
//设置状态栏文字为白色
window.setStatusBarVisibility(0);

网络访问

地址 https://harmonyos.51cto.com/posts/3382

导入插件

前端有 npm yarn 鸿蒙os使用gradle 

dependencies 依赖项 与 npm package.js 中 dependencies  devDependencies 类似

apply plugin: 'com.huawei.ohos.hap'
ohos {
    compileSdkVersion 4
    defaultConfig {
        compatibleSdkVersion 4
    }
}
//dependencies 依赖项 与 npm package.js 中 dependencies  devDependencies 类似
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
    testCompile 'junit:junit:4.12'
    /**
     * implementation 内部隐藏依赖项
     * compile 外部公开项目
     */
//    implementation 'com.zzrv5.zzrhttp:ZZRHttp:1.0.1'
    compile "com.squareup.okhttp3:okhttp:3.10.0"
}

路由

不同Page跳转

 

Intent secondIntent = new Intent();
Operation operation = new Intent.OperationBuilder( )
.withDeviceId("")//设备id
.withBundleName ( " com. example . customtimer")//包名字
.withAbilityName( " com. examp1e . customtimer . SecondaryAbility")//类名字
.build();//执行上面操作
secondIntent. setoperation(operation);
startAbility( secondIntent);//跳转

返回上一级

terminate();

数据存储

这里推荐一个kv键值对的方式 类似web端的 localStorage;具体用法看文档,这里简单演示一下

鸿蒙OS前端开发入门指南-鸿蒙开发者社区

package com.example.shangjinlieren.database;

import ohos.app.Context;
import ohos.data.DatabaseHelper;
import ohos.data.preferences.Preferences;

public class DbKv {
    private DatabaseHelper databaseHelper;
    private Context context;

    public DbKv( Context context) {
        this.context = context;
        getPreferences();
    }
    /**
     * 获取Preferences实例
     * preferences 设置参数
     * @param
     * @return
     */
    public Preferences getPreferences(){
        DatabaseHelper databaseHelper = new DatabaseHelper(this.context); // context入参类型为ohos.app.Context。
        String fileName = "user"; // fileName表示文件名,其取值不能为空,也不能包含路径,默认存储目录可以通过context.getPreferencesDir()获取。
        Preferences preferences = databaseHelper.getPreferences(fileName);
        return  preferences;
    }
}

 

Fraction跳转AbilitySlice

解决方案 如下 在new Fraction 页面的时候在AbilitySlice页面传入this就可以获取 present进行 AbilitySlice之间的跳转了

跳转当前ability别的 Slice
    abilitySlice.present(new MainMoneyListDetailSlice(),intent);
跳转其他ability      
           Operation operationBuilder = new Intent.OperationBuilder()
                        .withBundleName("com.example.shangjinlieren")
                        .withAbilityName("com.example.shangjinlieren.LoginAbility")
                        .build();
                intent.setOperation(operationBuilder);
                abilitySlice.startAbility(intent);

更新UI界面

  getUITaskDispatcher()
            .asyncDispatch(new Runnable() {
                @Override
                public void run() {
                //button 按钮对象
                 button.setText("dd");
                }
            });

自定义底部导航具备生命周期

地址https://harmonyos.51cto.com/posts/3151

网络图片

地址https://harmonyos.51cto.com/posts/3388

视频渲染

地址https://harmonyos.51cto.com/posts/3660

UI适配

地址https://harmonyos.51cto.com/posts/3329

java代码编写布局/参数

地址https://harmonyos.51cto.com/posts/3418

鸿蒙OS创建组件

1.0版本 地址https://harmonyos.51cto.com/posts/3421

2.0版本 https://harmonyos.51cto.com/posts/6099

java回调函数封装

https://harmonyos.51cto.com/posts/6194

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2021-7-15 11:13:54修改
3
收藏 5
回复
举报
3条回复
按时间正序
/
按时间倒序
鸿蒙张荣超
鸿蒙张荣超

👍👍👍 庆祝2021年第1天的最好方式,就是学习和研究鸿蒙!

回复
2021-2-12 01:18:59
Whyalone
Whyalone

这算是先开个坑?

回复
2021-2-22 13:50:49
老克
老克

在线蹲更新~

回复
2021-2-22 16:52:35
回复
    相关推荐