1.在登录或引导页面添加 “已阅读和同意用户使用协议和隐私政策” <LinearLayout android:layout_width="match_parent" android:layout_height="30dp" android:orientation="horizontal" android:gravity="center" > <CheckBox android: 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: 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: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/zhengce" android:textSize="14sp" /> </LinearLayout>
2.点击用户使用协议或隐私政策时,显示dialog弹窗
String str = initAssets(""); final View inflate = (mActivity).inflate(.dialog_xieyi_yinsi_style, null); TextView tv_title = (TextView) (.tv_title); tv_title.setText("隐私政策"); TextView tv_content = (TextView) (.tv_content); tv_content.setText(str); final Dialog dialog = new AlertDialog .Builder(mActivity) .setView(inflate) .show(); final params = ().getAttributes(); = 800; = 1200; ().setAttributes(params); ().setBackgroundDrawableResource();
3.将隐私政策和用户使用协议的文本放在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) { (); } return str; } public static String getString(InputStream inputStream) { InputStreamReader inputStreamReader = null; try { inputStreamReader = new InputStreamReader(inputStream, "UTF-8"); } catch (UnsupportedEncodingException e1) { (); } BufferedReader reader = new BufferedReader(inputStreamReader); StringBuffer sb = new StringBuffer(""); String line; try { while ((line = ()) != null) { (line); ("\n"); } } catch (IOException e) { (); } return (); }
主体内容的布局 dialog_xieyi_yinsi_style.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro xmlns:tools="/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: 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: 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: android:layout_width="match_parent" android:layout_height="40dp" android:layout_alignParentBottom="true" android:gravity="center" android:visibility="gone" > <Button android: 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:andro android:shape="rectangle"> <!-- 填充色 --> <solid android:color="@color/white" /> <!--描边、 线的宽度,颜色 --> <!--<stroke--> <!--android:width="1dp"--> <!--android:color="@color/colorMainColor" />--> <!-- 矩形圆角半径 --> <corners android:radius="10dp" /> </shape>