首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React本机状态条样式不能覆盖本机android状态栏样式

React本机状态条样式不能覆盖本机android状态栏样式
EN

Stack Overflow用户
提问于 2020-02-03 08:20:26
回答 1查看 221关注 0票数 0

我试图在componentDidMount上将状态条半透明设置为false,但它似乎不起作用。我这样做的原因是不同的(因为我使用的是react-native-bootsplash,这要求我拥有本地样式),但总的来说,它似乎不起作用。

styles.xml

代码语言:javascript
复制
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:textColor">#000000</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

<style name="BootTheme" parent="AppTheme">
    <item name="android:background">@drawable/bootsplash</item>
</style>

Login.js

代码语言:javascript
复制
componentDidMount(): void {
    .
    .
    StatusBar.setTranslucent(false);
    StatusBar.setBackgroundColor("#FFF");
}
.
.
.
render() {
    const Navigation = this.props.navigation;

    return (
        <>
            <StatusBar backgroundColor="white" barStyle="dark-content"/>
    .
    .
    .
}
EN

回答 1

Stack Overflow用户

发布于 2020-02-03 08:41:46

您可以定义两个状态条,一个是正常的,另一个是半透明的。然后,你可以用状态来控制它的情况。例如;

代码语言:javascript
复制
render() {

    return (

        <View>

            {
                this.state.translucency  ?

                    <View>
                        /* custom style for statusbar */
                        <View style={{backgroundColor: "black", height:statusBarHeight, opacity: 0.3}}/>
                        <StatusBar backgroundColor={statusbarColor} barStyle="light-content" />
                    </View>

                    :

                    <StatusBar />

            }

        </View>

    );

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60035455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档