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>
分类:
android-widget
标签:
android-widget
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库