Flutter中如何修改光标底部叶片状标识的颜色?
解决TextField光标底部蓝色叶片状标识改黑色的问题
你说的这个蓝色叶片状标识是文本选择手柄(selection handle),它是文本选择时用来调整选中范围的控件,也会默认显示在光标底部。你设置的cursorColor只控制光标竖线的颜色,要修改手柄的颜色,需要调整文本选择主题的相关属性。
方法一:单独给TextField设置
用Theme组件包裹你的TextField,通过textSelectionTheme指定手柄颜色:
Expanded( child: Padding( padding: const EdgeInsets.only(left: 38), child: Theme( data: Theme.of(context).copyWith( textSelectionTheme: const TextSelectionThemeData( selectionHandleColor: Colors.black, // 设置手柄为黑色 ), ), child: TextField( cursorColor: Colors.black, style: const TextStyle( color: Colors.black54, fontFamily: 'sen', fontSize: 15, ), decoration: const InputDecoration( border: InputBorder.none, hintText: "Type Message", hintStyle: TextStyle( color: Colors.black54, fontFamily: 'sen', fontSize: 15 ) ), ), ), ), ),
方法二:全局统一设置(可选)
如果想让整个App的文本选择手柄都变成黑色,直接在MaterialApp的主题里配置:
MaterialApp( theme: ThemeData( textSelectionTheme: const TextSelectionThemeData( selectionHandleColor: Colors.black, ), ), // 其他配置项 )
内容的提问来源于stack exchange,提问作者Ariana
相关产品推荐
相关产品推荐

