把Activity变成dialog弹出框

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

  • 修改 AndroidManifest.xml文件,如下
        <activity
       ......
            android:theme="@style/Theme.HalfTranslucent" />
   
  • 样式
    
    <style name="Theme.HalfTranslucent" parent="AppTheme.NoActionBar">
        "android:windowBackground">@color/half_transparent
        "android:colorBackgroundCacheHint">@null
        "android:windowIsTranslucent">true
    style>
  • 颜色
   
    <color name="half_transparent">#aa000000color>
  • 布局

<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>
  • 效果
    把Activity变成dialog弹出框_第1张图片

你可能感兴趣的:(Android)