as

Settings
Sign out
Notifications
Alexa
亚马逊应用商店
AWS
文档
Support
Contact Us
My Cases
新手入门
设计和开发
应用发布
参考
支持

expo-system-ui

expo-system-ui

@amazon-devices/expo-system-ui允许与位于React树之外的系统用户界面元素进行交互。特别是与根视图背景颜色交互。

安装

  1. package.json文件中添加JavaScript库依赖项。

    已复制到剪贴板。

     dependencies: {
         ...
         "@amazon-devices/expo-system-ui": "~2.0.0",
         "@amazon-devices/keplerscript-turbomodule-api": "~1.0.0",
     }
    
  2. 使用npm install命令重新安装依赖项。

示例

已复制到剪贴板。

import React, {useState} from 'react';
import {StyleSheet, View, Button} from 'react-native';
import * as SystemUI from '@amazon-devices/expo-system-ui';
import {ColorValue} from 'react-native';

export const App = () => {
  const [backgroundColor, setBackgroundColor] = useState<ColorValue | null>(
    '#0000ff',
  );

  const changeBackgroundColor = async (color: string | null) => {
    console.log(backgroundColor);
    await SystemUI.setBackgroundColorAsync(color);
    setBackgroundColor(await SystemUI.getBackgroundColorAsync());
  };

  return (
    <View style={[styles.container, backgroundColor ? {backgroundColor} : {}]}>
      <Button
        title="更改背景颜色"
        onPress={() =>
          changeBackgroundColor(
            backgroundColor === '#0000ff' ? '#ff0000' : '#0000ff',
          )
        }
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});

API参考

请查看以下专门文档页面,了解有关此库、API参考等的信息: 针对expo-system-ui的官方Expo文档(仅提供英文版)。

方法

方法 描述
getBackgroundColorAsync 获取根视图背景颜色
setBackgroundColorAsync 更改根视图背景颜色

支持的版本

程序包版本 基于 @amazon-devices/react-native-kepler版本
2.0.x 2.7.0 2.0.x

其他资源

有关其他库的信息,请参阅支持的第三方库和服务


Last updated: 2025年9月30日