zoukankan      html  css  js  c++  java
  • 鸿蒙开发基础(四)跨设备运行

    config.json

    "deviceType": ["tv", "wearable"]
    

    MainAbilitySlice

    public class MainAbilitySlice extends AbilitySlice {
    
        private DirectionalLayout myLayout = new DirectionalLayout(this);
    
        @Override
        public void onStart(Intent intent) {
            super.onStart(intent);
            myLayout.setOrientation(Component.VERTICAL);
            LayoutConfig config = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_PARENT);
            myLayout.setLayoutConfig(config);
            ShapeElement element = new ShapeElement();
            element.setRgbColor(new RgbColor(255, 255, 255));
            myLayout.setBackground(element);
    
            Text text = new Text(this);
            text.setLayoutConfig(config);
    
            if(DeviceInfo.getDeviceType().equals("tv")) {
                // 运行在TV上执行的代码
                text.setText("华为智慧屏");
                text.setTextColor(new Color(0xFFFF0000));
                text.setTextSize(200);
            } else if(DeviceInfo.getDeviceType().equals("wearable")) {
                // 运行在Wearable上执行的代码
                text.setText("华为智能手表");
                text.setTextColor(new Color(0xFF0000FF));
                text.setTextSize(50);
            }
            text.setTextAlignment(TextAlignment.CENTER);
            myLayout.addComponent(text);
    
            super.setUIContent(myLayout);
        }
    
        @Override
        public void onActive() {
            super.onActive();
        }
    
        @Override
        public void onForeground(Intent intent) {
            super.onForeground(intent);
        }
    }
    
    
  • 相关阅读:
    mysql事务
    mysql函数
    mysql自连接
    MYSQL添加外键关联
    SQL多表查询
    SQL数据完整性
    SQL limit
    SQL分组查询
    升级GCC 6.2编译LLVM的问题
    Quartz时SLF4J错误
  • 原文地址:https://www.cnblogs.com/cnyl/p/13917019.html
Copyright © 2011-2022 走看看