记录一下,方便记忆
一.Dialog
二.PopupWindow
请看另一篇:https://mp.csdn.net/postedit/82692365
三.Activity
四.BottomSheetDialog
BottomSheetDialog继承AppCompatDialog,AppCompatDialog继承Dialog。看到这里,应该知道BottomSheetDialog的一些特征。
BottomSheetDialog使用很方便,自定义View除外:
BottomSheetDialog bsd = new BottomSheetDialog( this );
//将要添加的布局文件
View rootView = View.inflate( this, R.layout.bottom_sheet_activity, null );
TextView title = rootView.findViewById( R.id.title );
title.setText( item.getName() );
TextView content = rootView.findViewById( R.id.content );
content.setText( item.getDemo() );
ImageView cancel = rootView.findViewById( R.id.cancel );
//取消点击事件
cancel.setOnClickListener( v1 -> bsd.dismiss() );
//将布局文件添加到BottomSheetDialog中
bsd.setContentView( rootView );
//显示
bsd.show();
bottom_sheet_activity.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/size_dp_43"
android:background="@drawable/button_gray_white"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingLeft="@dimen/size_dp_15"
android:paddingRight="@dimen/size_dp_15"
android:textColor="@color/font_color"
android:textSize="@dimen/text_size_14"/>
<ImageView
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="@null"
android:paddingLeft="@dimen/size_dp_10"
android:paddingRight="@dimen/size_dp_10"
android:src="@mipmap/arrow"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/size_dp_0.5"
android:background="@color/datum_background"
/>
<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/size_dp_10"
/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/size_dp_10"
/>
</LinearLayout>
其它方式持续更新…