Android APP 用户协议与隐私政策 圆角Dialog显示

1.在登录或引导页面添加 “已阅读和同意用户使用协议隐私政策”
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="horizontal"
    android:gravity="center"
    >

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:theme="@style/MyCheckBox"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="已阅读并同意"
        android:textSize="14sp"
        />
    <TextView
        android:id="@+id/tv_xieyi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/xieyi"
        android:textSize="14sp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="和"
        android:textSize="14sp"
        />
    <TextView
        android:id="@+id/tv_yinsi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/zhengce"
        android:textSize="14sp"
        />
</LinearLayout>

 

2.点击用户使用协议隐私政策时,显示dialog弹窗

String str = initAssets("yszc.txt");
final View inflate = LayoutInflater.from(mActivity).inflate(R.layout.dialog_xieyi_yinsi_style, null);
TextView tv_title = (TextView) inflate.findViewById(R.id.tv_title);
tv_title.setText("隐私政策");
TextView tv_content = (TextView) inflate.findViewById(R.id.tv_content);
tv_content.setText(str);
final Dialog dialog = new AlertDialog
        .Builder(mActivity)
        .setView(inflate)
        .show();
final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = 800;
params.height = 1200;
dialog.getWindow().setAttributes(params);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

 

3.将隐私政策yszc.txt和用户使用协议yhsyxy.txt的文本放在assets下

4.读取assets下的文件

/**
 * 从assets下的txt文件中读取数据
 */
public String initAssets(String fileName) {
    String str = null;
    try {
        InputStream inputStream = getAssets().open(fileName);

        str = getString(inputStream);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    return str;
}
public static String getString(InputStream inputStream) {
    InputStreamReader inputStreamReader = null;
    try {
        inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    BufferedReader reader = new BufferedReader(inputStreamReader);
    StringBuffer sb = new StringBuffer("");
    String line;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line);
            sb.append("\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sb.toString();
}

 

5.dialog主体内容的布局 dialog_xieyi_yinsi_style.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:background="@drawable/background_dialog_xieyi"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_above="@+id/ll_btn_bottom"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_marginBottom="15dp"
            >
            <TextView
                android:id="@+id/tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="用户使用协议"
                android:textSize="18sp"
                android:textColor="@color/colorBlack"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                />

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fadingEdgeLength="50dp"
                android:requiresFadingEdge="horizontal"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                >

                <TextView
                    android:id="@+id/tv_content"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:singleLine="false"
                    android:text=""
                    android:textColor="@color/colorBlack"
                    android:layout_marginTop="10dp"
                    />
            </ScrollView>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/ll_btn_bottom"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:visibility="gone"
            >
            <Button
                android:id="@+id/tv_cancle"

                android:layout_width="60dp"
                android:layout_height="30dp"
                android:text="关闭"
                android:textSize="15dp"
                android:textColor="@color/white"
                android:background="@drawable/blue_btn_bg"
                android:layout_marginBottom="5dp"
                />

        </LinearLayout>
    </RelativeLayout>
</LinearLayout>

 

6.布局中的圆角背景 drawable/background_dialog_xieyi.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- 填充色 -->
    <solid android:color="@color/white" />
    <!--描边、 线的宽度,颜色 -->
    <!--<stroke-->
    <!--android:width="1dp"-->
    <!--android:color="@color/colorMainColor" />-->
    <!-- 矩形圆角半径 -->
    <corners android:radius="10dp" />
</shape>
  • 6
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chailongger

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值