如何在Android所有界面上实现水印
来源:互联网 发布:xquartz2.7.9 mac 编辑:程序博客网 时间:2024/06/06 06:35
在一些对安全性要求较高的app中,会要求对所有的界面加上水印,防止截屏泄露客户信息,总体思路是获取底层的布局,在布局上add一个自定义的水印View,由于添加View必须要在setContentView之后,所以把添加水印的过程放在onStart中,并加上判断防止多次添加.
自定义水印布局
注:RotateTextView布局转自http://download.csdn.net/download/fangjxl/9485001
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#00000000"><LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="40dp" android:orientation="horizontal" > <RotateTextView android:id="@+id/fragment_tag11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:layout_marginLeft="20dp" android:text="@string/app_name" android:textColor="#22666666" android:textSize="22sp" app:degree="350dp" /> <RotateTextView android:id="@+id/fragment_tag12" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginLeft="20dp" android:text="@string/app_name" android:textColor="#22666666" android:textSize="22sp" app:degree="350dp" /> <RotateTextView android:id="@+id/fragment_tag13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginLeft="20dp" android:text="@string/app_name" android:textColor="#22666666" android:textSize="22sp" app:degree="350dp" /> <RotateTextView android:id="@+id/fragment_tag14" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginLeft="20dp" android:text="@string/app_name" android:textColor="#22666666" android:textSize="22sp" app:degree="350dp" /> </LinearLayout></LinearLayout></FrameLayout>
attr
<declare-styleable name="RotateTextView"> <attr name="degree" format="dimension" /> </declare-styleable>
java
RotateTextView
public class RotateTextView extends TextView { @Override public void setText(CharSequence text, BufferType type) { // TODO Auto-generated method stub super.setText(waterMark, type); } private static final int DEFAULT_DEGREES = 0; //水印文字 public static String waterMark = ""; private int mDegrees; public RotateTextView(Context context) { super(context, null); } public RotateTextView(Context context, AttributeSet attrs) { super(context, attrs, android.R.attr.textViewStyle); this.setGravity(Gravity.CENTER); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RotateTextView); mDegrees = a.getDimensionPixelSize(R.styleable.RotateTextView_degree, DEFAULT_DEGREES); a.recycle(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); } @Override protected void onDraw(Canvas canvas) { canvas.save(); canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop()); canvas.rotate(mDegrees, this.getWidth() / 2f, this.getHeight() / 2f); super.onDraw(canvas); canvas.restore(); } public void setDegrees(int degrees) { mDegrees = degrees; }}
Activity
@Override protected void onStart() { //判断是否已经添加过 if(isAdd){ }else { ViewGroup rootView = getRootView(this); View framView = LayoutInflater.from(this).inflate(R.layout.fragment_layout, null); rootView.addView(framView); isAdd=true; } super.onStart(); } //查找布局的底层 protected static ViewGroup getRootView(Activity context) { return (ViewGroup)context.findViewById(android.R.id.content); }
0 0
- 如何在Android所有界面上实现水印
- 如何在android手机上实现app开机自动运行启动(可以打开应用界面)。
- android在图片上加上水印
- asp.net如何在图片上加水印文字具体实现
- 如何在iPad上实现QQLive HD界面
- android 获取界面上所有控件
- android开发中怎么在界面上实现曲线图
- android开发中怎么在界面上实现曲线图
- Android自绘View界面布局实现文字水印效果
- ABAP--如何在打印报表上打印水印
- ABAP--如何在打印报表上打印水印
- ABAP--如何在打印报表上打印水印
- asp.net如何在图片上加水印文字
- asp.net如何在图片上加水印文字
- 如何在直播视频上添加水印Logo
- ABAP--如何在打印报表上打印水印
- 在图片上加上文字或水印的方法实现
- ASP.NET中实现在图片上打水印
- 提供一遍好文章(【前端福利】用grunt搭建自动化的web前端开发环境-完整教程)
- 一个可靠的USB设备插拔检测
- Docker和Docker-compose安装
- javascript本地对象、内置对象、宿主对象和自定义对象
- 前端知识大全
- 如何在Android所有界面上实现水印
- jdk中密钥和证书管理工具keytool使用说明
- PHP四种常见排序算法
- Android系统设置亮度实现流程
- js内置对象
- MSR和MRS
- 文件压缩为zip--C#
- Java编程:正则表达式Pattern、Matcher详解
- C++常用运算符重载