not*_*eal 3 android android-alertdialog android-dialogfragment
我应该如何创造这个设计的优秀部分?我正在使用 DialogFragment 在弹出窗口中执行此操作,但我无法实现顶部透明的效果。
按钮设计不过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>
Run Code Online (Sandbox Code Playgroud)
使用以下 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>
Run Code Online (Sandbox Code Playgroud)
结果:
星形必须位于布局之外的上部部分。
这很容易..我的朋友
只需将默认对话框背景设置为透明,就像我在 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))
}
}
Run Code Online (Sandbox Code Playgroud)
您的对话框 .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>
Run Code Online (Sandbox Code Playgroud)
背景_圆.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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3310 次 |
最近记录: |