flutter - Flutter - 如何更改搜索委托类中的文本颜色?
问题描述
我设法改变了hintStyle
-color
@override
ThemeData appBarTheme(BuildContext context) {
return ThemeData(
primaryColor: kPrimaryColor,
primaryIconTheme: IconThemeData(
color: Colors.white,
),
inputDecorationTheme: InputDecorationTheme(
hintStyle:
Theme.of(context).textTheme.title.copyWith(color: Colors.white),
),
);
}
但是,如果我在 appbar 搜索字段中输入一些内容,颜色仍然是黑色...
如何textcolor
在SearchDelegate
课堂上正确更改?
解决方案
使用 SearchDelegate 您可以自定义搜索的文本提示值和颜色以及查询的颜色和大小。为达到这个:
搜索的文本提示值 --> 您可以覆盖作为字符串的searchFieldLabel。
@override
String get searchFieldLabel => 'Your Custom Hint Text...';
搜索的颜色 --> 您可以使用 Theme 类的 hintColor 属性覆盖:
@override
ThemeData appBarTheme(BuildContext context) {
return Theme.of(context).copyWith(
hintColor: Colors.white,
);
}
查询的文本颜色和大小 --> 您需要覆盖委托的appBarTheme方法并更改您需要的内容。要更改查询的文本颜色,请设置header6的textTheme:
@override
ThemeData appBarTheme(BuildContext context) {
assert(context != null);
final ThemeData theme = Theme.of(context).copyWith(
textTheme: TextTheme(
headline6: TextStyle(
color: Colors.white,
fontSize: 18.0,
),
),
);
assert(theme != null);
return theme;
}
推荐阅读
- npm - npm 安装失败 - 角度 cli
- vba - 在另一个 Sub 中调用时脚本不解析单元格,excel Vba
- javascript - 显示从数据库中选择的值
- javascript - 动态创建具有唯一名称的多个 wavesurfer 对象
- amazon-web-services - 我们如何每天使用 Lambda 将文件从 S3 移动到 EC2?
- java - 检索 cookie 并在后续的 POST 请求中发送
- podio - 获取文件 ID 以从项目中获取文件 - Podio API
- php - 通过 WiFi 而非以太网的 PHP 服务器
- spring - 创建名为“requestMappingHandlerMapping”的 bean 时出错 Spring Boot
- extjs - ExtJS:如何在右键单击事件中获取所选网格记录的数据?