日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

android dialog懸浮和圓角

作者:jzlhll123 更新時(shí)間: 2022-08-30 編程語(yǔ)言

上半部分

<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);  //設(shè)置對(duì)話框背景透明 ,對(duì)于AlertDialog 就不管用了
        }

        if(setClickAction != null) setClickAction.invoke(view);

        android.view.WindowManager.LayoutParams p = dialog.getWindow().getAttributes();  //獲取對(duì)話框當(dāng)前的參數(shù)值
        p.width = context.getResources().getDimensionPixelSize(R.dimen.dailog_width);
        p.height = context.getResources().getDimensionPixelSize(R.dimen.dialog_height);
        dialog.setCanceledOnTouchOutside(true);// 設(shè)置點(diǎn)擊屏幕Dialog不消失
        dialog.getWindow().setAttributes(p);     //設(shè)置生效

        return dialog;
    }

通過設(shè)定dimens.xml的高寬來(lái)控制。

實(shí)現(xiàn)懸浮圓角dialog。而且是上下不同layout。

請(qǐng)?zhí)砑訄D片描述

原文鏈接:https://blog.csdn.net/jzlhll123/article/details/124426205

欄目分類
最近更新