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>