简体   繁体   English

如何更改 ListTile 的背景颜色?

[英]How to change background color of ListTile?

I am make settings page and want make like iOS settings (grey background and white tile).我正在制作设置页面,想要制作像 iOS 设置(灰色背景和白色瓷砖)。 I am try add Container so can add color to ListTile but always get error.我尝试添加容器,以便可以向 ListTile 添加颜色,但总是出错。

Anyone know how to add Container here?有人知道如何在此处添加容器吗?

  body: new SingleChildScrollView(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[

               Column(

                children: <Widget>[

                  ListTile(
                    leading: Icon(
                      Icons.person,
                      color: Colors.grey,
                    ),
                    title: Text("Account"),
                    trailing: Icon(Icons.keyboard_arrow_right),
                  ),

Just wrap your ListTile in a Container只需将ListTile包装在Container

  Container(
        color: Colors.grey[200],
        child: ListTile(
          leading: Icon(
            Icons.person,
            color: Colors.grey,
          ),
          title: Text("Account"),
          trailing: Icon(Icons.keyboard_arrow_right),
        ),
      )

I wrap the ListTile with a Material widget and set the color.我用Material小部件包装ListTile并设置颜色。 This will preserve the ripple effect of the listTile.这将保留 listTile 的涟漪效应。

eg.例如。

Material(
        color: Colors.grey[300],
              child: ListTile(
                title: Text('Hello')
              )

    );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM