简体   繁体   English

如何以实用的方式在Android中为应用程序创建叠加层作为水印?

[英]How to create an overlay for app as an watermark in Android pragmatically?

I want to make an app in which there will be a watermark that will be shown in every activity including the fragments if it exists.我想制作一个应用程序,其中会有一个水印,该水印将显示在每个活动中,包括片段(如果存在)。 I want to do that programmatically, without any XML for reducing redundant and boilerplate code.我想以编程方式做到这一点,没有任何用于减少冗余和样板代码的 XML。 The main purpose of it is that if I share an APK with anyone else then he cannot steal my APK because it contains a weird watermark everywhere.它的主要目的是,如果我与其他人共享一个 APK,那么他就无法窃取我的 APK,因为它到处都包含一个奇怪的水印。

I made a library for this to do that in a reusable way.我为此创建了一个,以可重用的方式做到这一点。 Here is documentation on how to use it in Java and Kotlin .这是有关如何在JavaKotlin 中使用它的文档。 First, initialize it from an activity from where you want to show the watermark-首先,从要显示水印的活动中对其进行初始化-

AppWaterMarkBuilder.doConfigure()
                .setAppCompatActivity(MainActivity.this)
                .setWatermarkProperty(R.layout.layout_water_mark)
                .showWatermarkAfterConfig();

Then you can hide and show it from anywhere in your app -然后你可以在你的应用程序的任何地方隐藏和显示它 -

  /* For hiding the watermark without callback*/
  AppWaterMarkBuilder.hideWatermark() 

  /* For showing the watermark without callback*/
  AppWaterMarkBuilder.showWatermark() 

预览

You need to create a canvas object then draw on top of that.您需要创建一个画布对象,然后在其上绘制。 Canvas would be of size of the screen and so you can then measure the size for watermark bitmap.画布将与屏幕大小相同,因此您可以测量水印位图的大小。 Then render it as a background image in the activity.然后将其渲染为活动中的背景图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM