在Flutter中,更改文本输入框(TextField
)中的选择光标颜色可以通过设置cursorColor
属性来实现。以下是一个简单的示例代码,展示了如何更改选择光标的颜色:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Change Cursor Color')),
body: Center(
child: TextField(
cursorColor: Colors.red, // 设置光标颜色为红色
decoration: InputDecoration(
hintText: 'Enter text here',
),
),
),
),
);
}
}
TextField
的一个属性,用于设置选择光标的颜色。通过上述方法,你可以轻松地在Flutter应用中更改选择光标的颜色,以适应不同的设计需求和用户体验优化。
领取专属 10元无门槛券
手把手带您无忧上云