[英]How Can I Change TextField Toolbar Style?
我想更改有關 TextField 工具欄的填充/背景顏色/字體大小。(當您長按 TextField 時,工具欄將顯示。)。 我該怎么辦? 我閱讀了 text_field.dart 和 text_selection.dart 但沒有找到答案。
我注意到當我使用 materialTapTargetSize: MaterialTapTargetSize.padded
它有助於更改文本字段工具欄的填充,但我發現更改它的樣式(例如背景顏色、跨度顏色等)沒有任何幫助。
這是我的代碼。 我簡化了代碼。 main.dart 中的這段代碼。 TextField 在另一個 dart 文件中。
MaterialApp(
theme: ThemeData(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
primaryColorBrightness: Brightness.light,
buttonTheme: ButtonThemeData(
minWidth: 0,
padding: EdgeInsets.all(0), // Notice this
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),home:SizedBox()
)
當我更改padding時,TextField Toolbar Padding也會更改。我有點困惑,主題未更改時如何更改它。 我發現 TextStyle 沒有任何幫助。
TextField(
style: CustomTextStyle.textField14TextStyle,
keyboardType: widget.keyboardType,
autocorrect: false,
enableInteractiveSelection: true,
decoration: InputDecoration(
hintText: _getHintText(),
hintStyle: CustomTextStyle.minorGray14TextStyle,
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: widget.isError ? Color(0xffbb424a) : Color(0xff333333)),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: widget.isError ? Color(0xffbb424a) : CustomColor.obviousTextColor),
),
contentPadding: EdgeInsets.symmetric(vertical: Global.isShortScreen ? 15 : 20),
),
onSubmitted: (text) {
if (widget.onSubmitted != null) {
widget.onSubmitted();
}
},
controller: widget.controller,
cursorColor: CustomColor.obviousTextColor,
)
我嘗試使用類似Material( child: Theme(data:ThemeData(),child:TextField())
但它不起作用。
要更改文本選擇顏色,您可以使用textSelectionTheme
光標線的cursorColor
光標下方氣泡的selectionHandleColor
selectionColor
高亮顏色
textSelectionTheme: _theme.textSelectionTheme.copyWith(
cursorColor: AppColors.purple,
selectionHandleColor: AppColors.purple,
selectionColor: AppColors.grey4,
),
要更改文本工具欄選項樣式,您可以使用button
textTheme
textTheme: _theme.textTheme
.copyWith(
button: _theme.textTheme.button?.copyWith(
//here
),
)
.apply(fontFamily: GoogleFonts.roboto().fontFamily),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.