我已经安装了Android支持库,但是在developer.android网站上说要在我的项目中实现它我需要编辑我没有的build.gradle文件,因为它是一个Unity项目.
我创建了一个build.gradle文件,复制了这个网站的内容:http://gradleplease.appspot.com/ 我将该文件放在我的Unity项目的根目录上,但当我尝试使用该库时,它不起作用
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method …Run Code Online (Sandbox Code Playgroud) 首先是我的问题的一些背景:我正在尝试创建一个系统覆盖类型视图(即在其他应用程序上绘制),它(目前)只是全屏纯色。我通过启动/停止服务来打开/关闭它。
这是我的代码到目前为止的样子(在服务内部):
public void onCreate() {
super.onCreate();
oView = new LinearLayout(this);
oView.setBackgroundColor(0x66ffffff);
PorterDuffColorFilter fil = new PorterDuffColorFilter(0xfff5961b, PorterDuff.Mode.MULTIPLY);
oView.getBackground().setColorFilter(fil);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
0 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(oView, params);
}
Run Code Online (Sandbox Code Playgroud)
这样,当我启动此服务时,我可以在其余的常规 android 使用中获得纯色。现在,我的具体问题是: 有什么方法可以使这种颜色在其背后的常规 android 使用中进行 MULTIPLY(想想 photoshop 混合模式)?
从我的代码中可以看出,我也尝试使用 PorterDuff 过滤器模式(它们的几种不同组合)来实现它,但徒劳无功。
这里有几个截图,希望能更好地解释这一点:
<-- 在同一屏幕上的预期结果。注意较深的颜色是如何叠加到下面的。
如您所见,我当前的代码仅抛出了一层纯色。我感谢所有的建议。提前致谢!