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

1.在登录或引导页面添加 “已阅读和同意用户使用协议隐私政策

    

    
    
    
    

 

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




    
        
            

            

                
            
        

        
            

 

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



    
    
    
    
    
    
    
    

你可能感兴趣的:(Android)