搭建直播平台,自定义VIew实现设置防截屏、添加水印
1.activity代码:MarkViewActivity
package com.zdmtech.backgroundtextdemo;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
/**
* 设置防截屏、添加水印
* */
public class MarkViewActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置防截屏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.activity_main);
initView();
}
public void initView() {
RelativeLayout reView = findViewById(R.id.reView);
// 添加水印
List<String> labels = new ArrayList<>();
labels.add("你");
labels.add("我");
labels.add("他");
reView.setBackground(new MarkBgView(MarkViewActivity.this, labels, -30, 14));
}
}
2.布局xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/reView"
android:orientation="vertical">
<TextView
android:id="@+id/tcContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="防截屏" />
</RelativeLayout>
以上就是 搭建直播平台,自定义VIew实现设置防截屏、添加水印,更多内容欢迎关注之后的文章
标签:layout,自定义,labels,水印,防截屏,import,android,VIew From: https://www.cnblogs.com/yunbaomengnan/p/17393969.html