簡體   English   中英

如何更改 Android Flutter 上的文本選擇顏色

[英]How to change text selection colour on Android Flutter

我需要幫助更改 Android Flutter 中的文本選擇顏色,因為它當前正在使用應用程序的 mainColor(黑色)。 在此處輸入圖像描述

如您所見,選擇顏色與文本顏色相同。 任何幫助將非常感激。 我嘗試了一切但無濟於事。 我想將文本選擇顏色更改為藍色或類似顏色。 代碼如下所示:

import 'package:musicofflinetemplate/services/IntentService.dart';

class AboutUsPage extends StatelessWidget {
  final GlobalProvider? global;
  AboutUsPage({@required this.global});
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      physics: BouncingScrollPhysics(),
      child: Column(
        children: [
          SizedBox(
            height: 50,
          ),
          Image(
            image: AssetImage("assets/res/icon/icon.png"),
            height: MediaQuery.of(context).size.width * 0.55,
          ),
          Padding(
            padding: EdgeInsets.only(left: 30, right: 40, top: 20, bottom: 10),
            child: SelectableText(
              global!.config.aboutText1!,
              textDirection: TextDirection.rtl,
              style: TextStyle(
                  fontSize: 20, height: 1.6, fontWeight: FontWeight.w500),
              /*textAlign: TextAlign.right,*/
            ),
          ),
          Padding(
            padding: EdgeInsets.only(left: 30, right: 40, top: 20, bottom: 10),
            child: SelectableText(
              global!.config.aboutText2!,
              textDirection: TextDirection.rtl,
              style: TextStyle(
                  fontSize: 20, height: 1.6, fontWeight: FontWeight.w500),
              /*textAlign: TextAlign.end,*/
            ),
          ),
          Padding(
            padding: EdgeInsets.only(left: 30, right: 40, top: 20, bottom: 10),
            child: SelectableText(
              global!.config.aboutText3!,
              textDirection: TextDirection.rtl,
              style: TextStyle(
                  fontSize: 20, height: 1.6, fontWeight: FontWeight.w500),
              /*textAlign: TextAlign.end,*/
            ),
          ),
          Padding(
            padding: EdgeInsets.only(left: 30, right: 40, top: 20, bottom: 10),
            child: SelectableText(
              global!.config.aboutText4!,
              textDirection: TextDirection.rtl,
              style: TextStyle(
                  fontSize: 20, height: 1.6, fontWeight: FontWeight.w500),
              /*textAlign: TextAlign.end,*/
            ),
          ),
          Padding(
            padding: EdgeInsets.only(left: 30, right: 40, bottom: 20, top: 10),
            child: Column(
              children: [
                Divider(),
                Material(
                  color: Colors.transparent,
                  child: InkWell(
                    splashColor: global!.config.mainColor!.withOpacity(0.2),
                    child: ListTile(
                      leading: Icon(
                        Icons.info,
                        color: global!.config.mainColor,
                      ),
                      title: Align(
                        alignment: Alignment(-1.1, 0),
                        child: Text(
                            "Version ${global!.packageInfo.versionNumber}",
                            style: TextStyle(
                                fontSize: 18, fontWeight: FontWeight.w500)),
                      ),
                      onTap: () {},
                    ),
                  ),
                ),
                if (global!.config.enableFacebook! ||
                    global!.config.enableTwitter! ||
                    global!.config.enableWebsite!)
                  Column(
                    children: [
                      Divider(),
                      SizedBox(
                        height: 30,
                      ),
                      Container(
                          width: MediaQuery.of(context).size.width,
                          child: Text("Connect with us",
                              style: TextStyle(
                                  fontSize: 24,
                                  fontWeight: FontWeight.w700,
                                  color: global!.config.mainColor))),
                    ],
                  ),
                SizedBox(
                  height: 20,
                ),
                if (global!.config.enableWebsite!)
                  Column(
                    children: [
                      Material(
                        color: Colors.transparent,
                        child: InkWell(
                          splashColor:
                              global!.config.mainColor!.withOpacity(0.2),
                          child: ListTile(
                            leading: Icon(
                              Icons.link,
                              size: 25,
                              color: global!.config.mainColor,
                            ),
                            title: Align(
                              alignment: Alignment(-1.1, 0),
                              child: Text("Visit our website",
                                  style: TextStyle(fontSize: 20)),
                            ),
                            onTap: () async {
                              await IntentService.openUrl(
                                  global!.config.website!);
                            },
                          ),
                        ),
                      ),
                      Divider(),
                    ],
                  ),
                if (global!.config.enableFacebook!)
                  Column(
                    children: [
                      Material(
                        color: Colors.transparent,
                        child: InkWell(
                          splashColor:
                              global!.config.mainColor!.withOpacity(0.2),
                          child: ListTile(
                            leading: Icon(Ionicons.logo_facebook,
                                size: 23, color: Color(0xff3b5998)),
                            title: Align(
                              alignment: Alignment(-1.1, 0),
                              child: Text("Like us on facebook",
                                  style: TextStyle(fontSize: 20)),
                            ),
                            onTap: () async {
                              await IntentService.openSocialUrl(
                                  handler: global!.config.facebookHandler!,
                                  type: 'facebook');
                            },
                          ),
                        ),
                      ),
                      Divider(),
                    ],
                  ),
                if (global!.config.enableTwitter!)
                  Column(
                    children: [
                      Material(
                        color: Colors.transparent,
                        child: InkWell(
                          splashColor:
                              global!.config.mainColor!.withOpacity(0.2),
                          child: ListTile(
                            leading: Icon(Ionicons.logo_twitter,
                                size: 23, color: Color(0xff00acee)),
                            title: Align(
                              alignment: Alignment(-1.1, 0),
                              child: Text("Follow us on twitter",
                                  style: TextStyle(fontSize: 20)),
                            ),
                            onTap: () async {
                              await IntentService.openSocialUrl(
                                  handler: global!.config.twitterHandler!,
                                  type: 'twitter');
                            },
                          ),
                        ),
                      ),
                    ],
                  ),
              ],
            ),
          )
        ],
      ),
    );
  }
}

您可以使用以下內容:

https://flutter.dev/docs/release/breaking-changes/text-selection-theme

ThemeData(
  cursorColor: Colors.red,
  textSelectionColor: Colors.green,
  textSelectionHandleColor: Colors.blue,
)

或者

ThemeData(
  textSelectionTheme: TextSelectionThemeData(
    cursorColor: Colors.red,
    selectionColor: Colors.green,
    selectionHandleColor: Colors.blue,
  )
)

ThemeData 是您的應用程序的主題。 你可以這樣提供:

在您的 MaterialApp 中:

 child: MaterialApp(
        theme: ThemeData(
          textSelectionTheme: TextSelectionThemeData(
            cursorColor: Colors.red,
            selectionColor: Colors.green,
            selectionHandleColor: Colors.blue,
          ),
        ),
        builder: ............

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM