gpt4 book ai didi

android - 总是在顶部布局不起作用

转载 作者:行者123 更新时间:2023-11-29 20:01:23 27 4
gpt4 key购买 nike

我想像往常一样在顶部制作一个图层,这样它就会出现在您可以看到的每个想法(所有应用程序和...)中,如下图所示:

enter image description here

在 ide(android studio) 中没有错误,但它不起作用,它只是显示一个没有 View 的白屏,在 logcat 中可以看到以下错误

E/art: setrlimit(RLIMIT_CORE) failed for pid 18140: Operation not permitted

list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tpck.myapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity android:name=".AAA"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

<service
android:name="HUD"
android:exported="false"
/>
</application>

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

</manifest>

主 Activity

package com.tpck.myapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class AAA extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent svc = new Intent(this, OverlayShowingService.class);
startService(svc);
}
}

服务

package com.tpck.myapp;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Toast;

public class HUD extends Service {
HUDView mView;

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
super.onCreate();

Toast.makeText(getBaseContext(),"onCreate", Toast.LENGTH_LONG).show();
mView = new HUDView(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(

WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.TOP;
params.setTitle("Load Average");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
}

@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(getBaseContext(),"onDestroy", Toast.LENGTH_LONG).show();
if(mView != null)
{
((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mView);
mView = null;
}
}
}

class HUDView extends ViewGroup {
private Paint mLoadPaint;

public HUDView(Context context) {
super(context);
Toast.makeText(getContext(),"HUDView", Toast.LENGTH_LONG).show();

mLoadPaint = new Paint();
mLoadPaint.setAntiAlias(true);
mLoadPaint.setTextSize(10);
mLoadPaint.setARGB(255, 255, 0, 0);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawText("Hello World", 5, 15, mLoadPaint);
}

@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
}

@Override
public boolean onTouchEvent(MotionEvent event) {


Toast.makeText(getContext(),"onTouchEvent", Toast.LENGTH_LONG).show();
return true;
}
}

最佳答案

看看Floaties .这个库完全可以满足您的需求。

关于android - 总是在顶部布局不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36265948/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com