自定義對話框

  1. style文件
<!--全屏對話框-->
    <style name="DialogFullWindowStyle" parent="android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
  1. drawable文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/white" />
    <corners android:radius="4dp" />
</shape>
  1. layout布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="320dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        tools:background="#123">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/iv_driverCover"
            android:layout_marginTop="-45dp"
            android:background="@drawable/rect_background_white"
            android:padding="@dimen/size_defaultActivityContentLineMargin">

            <TextView
                android:id="@+id/tv_driverName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="50dp"
                android:textColor="@color/color_textOrange"
                android:textSize="@dimen/size_textDefault"
                tools:text="司機名字" />

            <TextView
                android:id="@+id/tv_carId"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tv_driverName"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="7dp"
                android:textColor="@color/color_defaultTextDarker"
                android:textSize="@dimen/size_textDefault"
                tools:text="京A88888" />

            <TextView
            android:id="@+id/tv_driverPhone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_carId"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="7dp"
            android:textColor="@color/color_defaultTextDark"
            android:textSize="@dimen/size_textDefault"
            tools:text="18333574728" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_below="@id/tv_driverPhone"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/btn_cancel"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/comm_press_background"
                    android:gravity="center"
                    android:text="取消"
                    android:textSize="@dimen/size_textDefault" />

                <Button
                    android:id="@+id/btn_ok"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/comm_press_background"
                    android:gravity="center"
                    android:text="確定"
                    android:textColor="@color/color_textOrange"
                    android:textSize="@dimen/size_textDefault" />
            </LinearLayout>
        </RelativeLayout>

        <ImageView
            android:id="@+id/iv_driverCover"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_centerHorizontal="true"
            android:src="@mipmap/default_diver_cover"
            tools:background="#123" />
    </RelativeLayout>
</RelativeLayout>
  1. java代碼
private void showUserInfoDialog(DriverBean bean) {

        Dialog view = new Dialog(this, R.style.DialogFullWindowStyle);// 創(chuàng)建自定義樣式dialog

        view.setCancelable(false);// 不可以用“返回鍵”取消
        view.setContentView(R.layout.dialog_show_driver_info);// 設(shè)置布局

        ImageView iv_driverCover = (ImageView) view.findViewById(R.id.iv_driverCover);
        TextView tv_driverName = (TextView) view.findViewById(R.id.tv_driverName);
        TextView tv_carId = (TextView) view.findViewById(R.id.tv_carId);
        TextView tv_driverPhone = (TextView) view.findViewById(R.id.tv_driverPhone);
        Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
        Button btn_ok = (Button) view.findViewById(R.id.btn_ok);

        ImageLoader.getInstance().displayImage(bean.getHeadUrl(), iv_driverCover,
                ImageLoaderUtils.loadImage(this, cUtils.dp2px(100), R.mipmap.default_diver_cover));
        tv_driverName.setText(bean.getName());
        tv_carId.setText(bean.getDriverNum());
        tv_driverPhone.setText(StringUtils.splitString(bean.getPhone(), "-", StringUtils.SPLIT_TYPE_1));

        view.show();

        btn_cancel.setOnClickListener(v -> {
            view.dismiss();
            mQRCodeView.startSpot();
        });
        btn_ok.setOnClickListener(v -> {
            view.dismiss();
            OutingRepertoryActivity_.intent(ToScanQRCodeActivity.this).whichPage(OutingRepertoryActivity_.Page_Out).driverBean(bean).start();
            animUtils.leftInAnimation(ToScanQRCodeActivity.this);
            mQRCodeView.onDestroy();
            finish();
        });
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容