【问题标题】:CardView corners not rounded in an AlertDialog在 AlertDialog 中没有圆角的 CardView 角
【发布时间】:2015-05-21 18:57:32
【问题描述】:

我正在创建一个AlertDialog,该对话框的自定义布局是CardView(卡片是 xml 布局的根):

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/moreInfoCard"
    android:layout_gravity="center"
    app:cardCornerRadius="12dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    //my layout content

</android.support.v7.widget.CardView>

当我显示对话框时,卡片的角是圆角的,但角的背景不是透明的。

我该如何解决这个问题?提前谢谢你。

【问题讨论】:

  • 试试alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
  • 完美!你救了我 ;-) 非常感谢!
  • @Blackbelt :它应该作为答案发布

标签: android android-layout rounded-corners android-cardview


【解决方案1】:

调用alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transpare‌​nt);AlertDialog 的背景设置为透明即可

【讨论】:

  • 但这不允许设置根的边距
  • 为什么不呢?它的作用是链接背景?它与 margin 有什么关系? @梅里安
  • 我真的知道为什么,但是当我尝试在卡片视图上添加边距时它不适用,并且在我评论此行作为背景后边距工作正常
猜你喜欢
  • 1970-01-01
  • 2012-09-12
  • 1970-01-01
  • 2022-12-10
  • 2018-03-16
  • 1970-01-01
  • 1970-01-01
  • 2018-06-23
  • 2023-04-03
相关资源
最近更新 更多