简体   繁体   English

按下Pressable时如何更改文本颜色

[英]How to change text color when Pressable pressed

I have a Pressable with a Text inside and i want to change the color of the text when the pressable is pressed (it is ok for Pressable's backgourndcolor but not for Text) I tried something like:我有一个 Pressable 里面有一个文本,我想在按下 pressable 时更改文本的颜色(对于 Pressable 的 backgourndcolor 是可以的,但对于 Text 则不行)我尝试了类似的方法:

<Pressable
                    style={({ pressed }) => [
                        {
                            backgroundColor: pressed
                                ? colors.PRIMARY_COLOR_DARK
                                : colors.MAIN_BACKGROUND,
                        },
                        styles.playVideosButton,
                    ]}
                    onPress={() => console.log("Dossier")}>
                    {({ pressed }) => {
                        <Text
                            style={[
                                {
                                    color: pressed
                                        ? colors.WHITE_TEXT
                                        : colors.PRIMARY_COLOR_DARK,
                                },
                                styles.buttonText,
                            ]}>
                            Lancer les vidéos
                        </Text>;
                    }}
                </Pressable>

With this code Text desappears使用此代码文本消失

Apologies after more thorough testing the original script worked - as long as there are no color changes inside styles.buttonText.抱歉,经过更彻底的测试,原始脚本可以正常工作 - 只要 styles.buttonText 中没有颜色变化。

{({ pressed }) => (
                    <Text
                        style={[
                            {
                                color: pressed
                                    ? colors.WHITE_TEXT
                                    : colors.PRIMARY_COLOR_DARK,
                            },
                            styles.buttonText,
                        ]}>
                        Dossier
                    </Text>
                )}

暂无
暂无

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

相关问题 在按下 Pressable 按钮组件时,我将按钮的 backgroundColor 更改为不同的颜色。 如何添加某种动画? - While a Pressable button component is pressed, I change the backgroundColor of a buton to a different color. How can I add some sort of animation? 什么是使一个 Pressable 的文本颜色从三个中改变的最佳方法<Pressable/> s - What is the best best way to make one Pressable's text color change out of three <Pressable/>s 在React Native FlatList中按下组件时如何更改其颜色 - How to change color of an component when its pressed in React Native FlatList 在 React Native 中按下时如何更改多个按钮的颜色 - How to change multiple buttons color when pressed in React Native 如何为 React Native Pressable 配置波纹颜色? - How to configure the ripple color for a React Native Pressable? 测试 Pressable 的按下状态 - Testing the pressed state of a Pressable 如何根据在 React Native 中按下哪个 Pressable 来显示图标? - How to show icon depending on which Pressable is pressed in React Native? 当我在 reactnative 中使用 map 函数创建组件时,如何在 Pressable 中将颜色作为默认值? - How can I give a color as a defalut in Pressable when I create a component using the map function in reactnative? 在React Native中按下按钮时如何更改FlatList项目背景颜色 - How can i change the FlatList item background color when button is pressed in React Native React native 如何从 Pressable/Text 中获取价值 - React native How to get value from Pressable/Text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM