简体   繁体   English

如何在 react-native 样式的组件中使用不透明度?

[英]How can i use opacity in react-native styled components?

i'm tring to use opacicy with react-native and styled-components我正在尝试对 react-native 和 styled-components 使用不透明性

I want to make it look lighter by using opacity for the background color.我想通过使用不透明度作为背景颜色使它看起来更亮。

but when i use my code nothing happend但是当我使用我的代码时什么也没发生

how can i use that?我该如何使用它?

this is my code这是我的代码

    const CheckLabel = styled.Text`
    color: white;
    font-weight: bold;
    font-size: 13px;
    `;

    const NicknameButton = styled.TouchableOpacity`

    background: #08cfb4;
    opacity: 0.33;
    `;


    const Nickname = () => {

    return (
    <NicknameButton onPress={confirmname}>
    <CheckLabel>check</CheckLabel>
    </NicknameButton>
    )
    }

Your code seems right.您的代码似乎正确。 I tested it and it works, just hit the button and you will be able to see the same color with opacity.我对其进行了测试,它可以工作,只需点击按钮,您就可以看到具有不透明度的相同颜色。

As of now we can use activeOpacity as below截至目前,我们可以使用activeOpacity如下

 <NicknameButton activeOpacity={0.85} onPress={confirmname}>
    <CheckLabel>check</CheckLabel>
 </NicknameButton>

Little bit R&D一点点研发

As per my knowledge with following version据我所知,以下版本

"react": "16.13.1"
"react-native": "0.63.4",
"styled-components": "^5.2.1"

if we try below code then it will throw error如果我们尝试下面的代码,那么它会抛出错误

export const TouchableOpacity = styled.TouchableOpacity`
  active-opacity : 0.85;  
  height:100px;
  width:100px;
`

在此处输入图像描述

if we try below如果我们在下面尝试

export const TouchableOpacity = styled.TouchableOpacity`
  opacity : 0.85;  
  height:100px;
  width:100px;
`

then it will set opacity to view by default not while onPress然后它将不透明度设置为默认查看而不是 onPress

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM