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);
        }
    }
    
    
  • 相关阅读:
    随机数模块(random)
    时间模块(time)
    collection模块 1
    collection模块
    re模块
    正则
    Bootstrap 关于下拉菜单的使用
    Bootstrap 关于Glyphicons 字体图标的使用
    oracle拼音排序
    ajax缓存问题
  • 原文地址:https://www.cnblogs.com/cnyl/p/13917019.html
Copyright © 2011-2022 走看看