小编S M*_*han的帖子

为什么我的按钮采用“colorPrimary”作为默认背景颜色?

 <Button
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:text="Explore"
    android:id="@+id/btn_dialog"
    android:gravity="center_vertical|center_horizontal"
    android:layout_below="@+id/text_dialog"
    android:layout_marginBottom="20dp"
    android:layout_centerHorizontal="true"
    android:textColor="#ffffff" />
Run Code Online (Sandbox Code Playgroud)

这是我的 color.xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#00ccff</color>
    <color name="colorPrimaryDark">#00ccff</color>
    <color name="colorAccent">#00ccff</color>
    <color name="darkPrimary">#212121</color>
    <color name="darkPrimaryDark">#000000</color>
    <color name="whitecolor">#FFFFFF</color>
    <color name="switchcolor">#f0f0f0</color>
</resources>
Run Code Online (Sandbox Code Playgroud)

样式文件如下:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Run Code Online (Sandbox Code Playgroud)

当我尝试像这样设置背景颜色时:android:background="#f0f0f0",背景颜色没有变化。我正在尝试修复大约一个小时左右。请提供任何帮助。

xml android button

4
推荐指数
1
解决办法
2435
查看次数

如何在flutter中创建自定义Dialog

我想创建一个自定义对话框,如下所示。我可以创建一个带有两个按钮(正按钮和负按钮)的普通对话框。但是我搜索了很多关于创建自定义对话框(如下所示)的信息,但没有成功。

在此输入图像描述

showAlertDialog(BuildContext context) {

    // set up the buttons
    Widget cancelButton = FlatButton(
      child: Text("Cancel"),
      onPressed:  () {},
    );
    Widget continueButton = FlatButton(
      child: Text("Continue"),
      onPressed:  () {},
    );

    // set up the AlertDialog
    AlertDialog alert = AlertDialog(
      title: Text("Action"),
      content: Text("Would you like to continue learning how to use Flutter alerts?"),
      actions: [
        cancelButton,
        continueButton,
      ],
    );

    // show the dialog
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }
Run Code Online (Sandbox Code Playgroud)

现在我希望将这些按钮和图像作为对话框的子项,并使用底部的图标按钮“X”来关闭对话框。任何帮助表示赞赏。我是颤振的完全初学者。

dialog flutter

4
推荐指数
1
解决办法
8122
查看次数

如何在 Flutter 中以圆形头像显示选取的图像?

我有以下代码可以启动图像选择器以从图库中选择图像。

File _image;
  final picker = ImagePicker();

  Future getImage() async {
    final pickedFile = await picker.getImage(source: ImageSource.gallery);

    setState(() {
      _image = File(pickedFile.path);
    });
  }
Run Code Online (Sandbox Code Playgroud)

选择图像后,我希望该图像显示在已经存在的CircleAvatar. 上面的方法 getImage() 被调用如下:

                InkWell(
                        onTap: getImage,
                        child: CircleAvatar(
                          backgroundColor: Colors.black,
                          radius: 40.0,
                          child: CircleAvatar(
                            radius: 38.0,
                            child: ClipOval(
                              child: Image.asset('images/newimage.png'),
                            ),
                            backgroundColor: Colors.white,
                          ),
                        )
                    ),
Run Code Online (Sandbox Code Playgroud)

我有一个ClipOval是 的孩子,CircleAvatar并且有一个默认的 AssetImage 作为它的孩子。我不知道如何用从图库中挑选的图像替换这个占位符图像!任何帮助表示赞赏。

flutter imagepicker

4
推荐指数
2
解决办法
4217
查看次数

标签 统计

flutter ×2

android ×1

button ×1

dialog ×1

imagepicker ×1

xml ×1