把Activity变成dialog弹出框

就是设置Activity背景半透明,只需要修改theme 就可以了

  • 修改 AndroidManifest.xml文件,如下
        <activity
       ......
            android:theme="@style/Theme.HalfTranslucent" />
   
  • 样式
    <!-- 弹出窗体样式 -->
    <style name="Theme.HalfTranslucent" parent="AppTheme.NoActionBar">
        <item name="android:windowBackground">@color/half_transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>
  • 颜色
   <!-- 半透明颜色 -->
    <color name="half_transparent">#aa000000</color>
  • 布局
<?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="match_parent"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/dialog_marginTopAndBottom"
            android:layout_marginLeft="@dimen/dialog_marginLeftAndRight"
            android:layout_marginRight="@dimen/dialog_marginLeftAndRight"
            android:layout_marginTop="@dimen/dialog_marginTopAndBottom"
            android:background="@drawable/bg_round_white"
            android:gravity="center"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:layout_marginTop="20dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:paddingLeft="20dp"
                    android:text="@string/cancel_work"
                    android:textColor="@color/color_06"
                    android:textSize="@dimen/font_size_10"/>

            </LinearLayout>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@drawable/ic_line"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="65dp"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@color/color_07"
                    android:gravity="center_vertical"
                    android:minWidth="@dimen/dialog_minWidth"
                    android:paddingBottom="5dp"
                    android:paddingLeft="12dp"
                    android:paddingTop="5dp"
                    android:text="@string/cancelReason"
                    android:textColor="@color/color_06"
                    android:textSize="@dimen/font_size_06"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="20dp"
                    android:layout_marginTop="5dp"
                    android:background="@color/color_09"
                    >

                    <Spinner
                        android:id="@+id/spinner_cancelReason"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/spinner_height"
                        android:layout_gravity="top|left"
                        android:background="@drawable/bg_spinner_black"
                        android:overlapAnchor="false"
                        android:padding="0dp"
                        />
                </LinearLayout>

            </LinearLayout>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@drawable/ic_line"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@color/color_07"
                    android:gravity="center_vertical"
                    android:minWidth="@dimen/dialog_minWidth"
                    android:paddingBottom="5dp"
                    android:paddingLeft="12dp"
                    android:paddingTop="5dp"
                    android:text="@string/remark"
                    android:textColor="@color/color_06"
                    android:textSize="@dimen/font_size_06"/>

                <EditText
                    android:id="@+id/edt_remark"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="20dp"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/bg_input"
                    android:gravity="top|left"
                    android:inputType="textMultiLine"
                    android:maxLength="500"
                    android:minLines="2"
                    android:minWidth="300dp"
                    android:padding="8dp"/>
            </LinearLayout>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@drawable/ic_line"/>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:background="@drawable/ic_line"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/dialog_button_height"
                android:gravity="center_horizontal">

                <TextView
                    android:id="@+id/tv_submit"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/bg_dialog_left_selector"
                    android:gravity="center"
                    android:text="@string/sureCancel"
                    android:textColor="@color/color_02"
                    android:textSize="@dimen/font_size_08"/>

                <ImageView
                    android:id="@+id/iv_verticalLine"
                    android:layout_width="0.5dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/ic_line_vertical"/>

                <TextView
                    android:id="@+id/tv_cancel"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/bg_dialog_right_selector"
                    android:gravity="center"
                    android:text="@string/cancel"
                    android:textColor="@color/color_06"
                    android:textSize="@dimen/font_size_08"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>
  • 效果
    在这里插入图片描述
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值