gpt4 book ai didi

java - 服务背景

转载 作者:行者123 更新时间:2023-11-29 18:44:06 24 4
gpt4 key购买 nike

代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@null"
android:id="@+id/relativelayout"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<Button
android:id="@+id/button5"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_marginEnd="9dp"
android:layout_toStartOf="@+id/button12"
android:background="@drawable/service_button_background"
android:text="Akash" />

<Button
android:id="@+id/button6"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_above="@+id/button5"
android:layout_alignStart="@+id/button7"
android:background="@drawable/service_button_background"
android:text="Sanjana" />

<Button
android:id="@+id/button7"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignStart="@+id/button5"
android:layout_below="@+id/button5"
android:layout_marginStart="19dp"
android:background="@drawable/service_button_background"
android:text="Sahana" />

<Button
android:id="@+id/button12"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_above="@+id/button5"
android:layout_alignParentEnd="true"
android:layout_marginBottom="30dp"
android:background="@drawable/service_button_background"
android:text="Akash" />

<Button
android:layout_width="70dp"
android:background="@drawable/service_button_background"
android:text="Akash"
android:layout_height="70dp"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/button7"
android:layout_marginTop="30dp"
android:id="@+id/button11" />

代码

public class FloatingWindow extends Service{
WindowManager wm;
RelativeLayout ll;
LayoutInflater li;

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
final View myview;
li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
wm = (WindowManager) getSystemService(WINDOW_SERVICE);


WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_INPUT_METHOD |
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,// | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);

/////////////////////////Another params


params = new WindowManager.LayoutParams(
750,1250,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);

params.gravity = Gravity.RIGHT | Gravity.CENTER;
myview = li.inflate(R.layout.service_pie, null); // your layout here

wm.addView(myview, params);
params.x = 0;
params.y = 0

}

@Override
public void onDestroy() {
super.onDestroy();
stopSelf();
}

我已将主布局背景设置为 null 但它仍然存在...就像我如何删除它...意味着我有此服务,当我启动该服务时,此 Activity 将被夸大...但我想要只有按钮被充气而不是整个 Activity ......我如何实现这一点...................................... ...........................................................

最佳答案

试试这个解决方案

list 中添加这个

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

然后在您的启动器 Activity 或任何基本 Activity 中添加这些权限

 private static final int CODE_DRAW_OVER_OTHER_APP_PERMISSION = 2084;

onCreate() 中添加这个

if (SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, CODE_DRAW_OVER_OTHER_APP_PERMISSION);
//finish();
}

处理请求权限

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CODE_DRAW_OVER_OTHER_APP_PERMISSION) {
if (SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, CODE_DRAW_OVER_OTHER_APP_PERMISSION);
} else {
// do stuff here
}
}
}

然后启动您的服务并在服务类中执行此操作,检查下面的链接并分别执行您的操作 https://medium.com/@kevalpatel2106/create-chat-heads-like-facebook-messenger-32f7f1a62064

关于java - 服务背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52365531/

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