selectable 设置不生效
来源:7-3 Text 使用占比最高的组件,使用简单,深入复杂

西瓜一号
2024-06-21
对照的写的
代码没错,就是这个设置不生效
长按,双击都试了,没反应
点击事件,长按事件也不触发
是不是安卓模拟器要设置什么?默认是不能操作模拟器
学完text组件,上面没反应的又都可以了
import React from "react";
import { StyleSheet, Text, View } from "react-native";
export default () => {
return (
<View style={s.root}>
<Text
style={s.txt}
//默认是0
numberOfLines={1}
//clip 多余的剪掉
// tail 尾部省略 默认值
// head 头部省略
// middle 中间省略
ellipsizeMode='tail'
// 是否可选中 默认false
selectable={true}
// 选中后背景颜色
selectionColor='red'
onPress={() => {
console.log(`onPress,,,,,,`)
}}
onLongPress={() => {
console.log(`onLongPress,,,,,,`)
}}
//是否跟随系统字号 默认是true
allowFontScaling={false}
>
123456789
{/* <Text style={s.innerText}>sadhjk</Text> */}
</Text>
</View>
);
}
const s = StyleSheet.create({
root: {
width: '100%',
height: '100%',
backgroundColor: '#f0f0f0',
},
txt: {
fontSize: 34,
fontWeight: 'bold',
fontFamily: '',
backgroundColor: '#c0c0c0',
height: 200,
textAlign: 'center',
textAlignVertical: 'center', //垂直方向居中
//需要一起使用
textDecorationStyle: 'solid', // solid:线 搭配使用
textDecorationLine: 'underline', //underline:下划线 line-through:删除线
//需要一起使用
textShadowColor: 'red',
textShadowRadius: 10,
textShadowOffset: { width: 4, height: 4 }
},
// 嵌套文字 字号,颜色 不写就会沿用外面的样式,不能写pandding,margin
innerText: {
fontSize: 64,
color: 'red',
fontWeight: 'bold',
},
});
写回答
2回答
-
FE大公爵
2024-06-27
我在本地测试了你的代码,是OK的。点击和长按都是可以的
00 -
FE大公爵
2024-06-23
现在具体的问题是什么。如果代码不长,可以贴到评论区,如果代码多就发到QQ群吧032024-06-27
相似问题
动画效果没展示
回答 1
侧拉菜单怎么从右边弹出
回答 1