Android的对话框DialogFragment指定弹窗口大小,设置圆角

复制代码
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
      @Nullable Bundle savedInstanceState) {
    getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//1.必须设置dialog的window背景为透明颜色,不然圆角无效或者是系统默认的颜色
    return inflater.inflate(R.layout.dialog_pay_sure_alert, container);
  }

<FrameLayout  //2.必须布局文件最外层包裹一层,这样才能显示指定的对话框大小,比如这里的 380dp x 205dp
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="380dp"
android:layout_height="205dp"
android:paddingBottom="21dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"  //最好设置一些padding,有时候可能因为没有padding,圆角被子控件覆盖而无效
android:background="@drawable/bg_promo_input_dialog">
</android.support.constraint.ConstraintLayout>
</FrameLayout>

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid
android:color="@color/white"/>
<corners android:radius="20dp"/>
</shape>
</item>
</layer-list>
 
复制代码

 

posted @   yongfengnice  阅读(2611)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示