上半部分
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:topLeftRadius="8dp"
android:topRightRadius="8dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"
/>
<solid android:color="#f9f9fc"/>
</shape>
下半部分
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:topLeftRadius="0dp"
android:topRightRadius="0dp"
android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
/>
<solid android:color="@android:color/white"/>
</shape>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimens/dailog_width"
android:layout_height="@dimens/dailog_height"
android:orientation="vertical">
<LinearLayout corner_top>
</LinearLayout>
<View android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#f0f2f7"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:background="@drawable/corner_bottom"
android:gravity="end|center_vertical"
android:orientation="horizontal">
....
</LinearLayout>
</LinearLayout>
private Dialog createDialog(Context context, int layoutId, Action1<View> setClickAction) {
View view = LayoutInflater.from(context).inflate(layoutId, null);
ImageView icon = view.findViewById(R.id.dialog_icon);
icon.setImageDrawable(context.getResources().getDrawable(drawableId));
TextView headTv = view.findViewById(R.id.dialog_head);
headTv.setText(this.head);
TextView bodyTv = view.findViewById(R.id.dialog_body);
bodyTv.setText(this.body);
final Dialog dialog = new Dialog(context);
dialog.setContentView(view);
if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
}
if(setClickAction != null) setClickAction.invoke(view);
android.view.WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
p.width = context.getResources().getDimensionPixelSize(R.dimen.dailog_width);
p.height = context.getResources().getDimensionPixelSize(R.dimen.dialog_height);
dialog.setCanceledOnTouchOutside(true);
dialog.getWindow().setAttributes(p);
return dialog;
}
通过设定dimens.xml的高宽来控制。
实现悬浮圆角dialog。而且是上下不同layout。
|