gpt4 book ai didi

android - 如何创建具有透明部分的 DialogFragment?

转载 作者:行者123 更新时间:2023-12-05 00:16:34 26 4
gpt4 key购买 nike

我应该如何创造这个设计的优越部分?
我正在使用 DialogFragment 在弹出窗口中执行此操作,但无法实现顶部透明的效果。

enter image description here

按钮设计但 background_circle:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid
android:color="#fff"/>

</shape>

使用以下 XML 文件 my_dialog:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:padding="10dp"
android:orientation="vertical"
android:background="#fff"
android:gravity="center">

<TextView
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text long text"
/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/>

</LinearLayout>


<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/background_circle"
android:padding="3dp"
android:src="@drawable/ic_empty_star"/>
</RelativeLayout>

结果:

enter image description here

星号必须与布局之外的上部。

最佳答案

这很容易..我的 friend

enter image description here

只需将默认对话框背景设置为透明,就像我在 onStart() 中所做的那样

class TestDialog: DialogFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.my_dialog, container)
}

override fun onStart() {
super.onStart()
// if you want your dialog's width/height match device screen's width/height
// dialog?.window?.setLayout(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.WRAP_CONTENT
// )

dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}
}

您的对话框 .xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:padding="10dp"
android:orientation="vertical"
android:background="#fff"
android:gravity="center">

<TextView
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text long text"
/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/>

</LinearLayout>


<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/background_circle"
android:padding="3dp"
android:src="@drawable/ic_account_circle_black_54dp"/>

</RelativeLayout>

background_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid
android:color="#fff"/>

</shape>

关于android - 如何创建具有透明部分的 DialogFragment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58633351/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com