Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 系统覆盖窗口未按预期工作_Java_Android - Fatal编程技术网

Java 系统覆盖窗口未按预期工作

Java 系统覆盖窗口未按预期工作,java,android,Java,Android,我正在开发一个应用程序,它可以在所有应用程序的顶部绘制一个窗口。基本上我想做一个像这样的应用。为此,我想开发一款可以在所有应用程序上显示文本视图的应用程序(只是为了测试我的想法)。我是android新手,这是我的第二个应用程序。此外,在学习完udacity android基础课程后,我正在自学 我有一个带有TextView的MainActivity java文件。当用户触摸文本视图时,它将发送到屏幕上的java文件,该文件从服务扩展。到目前为止,我的应用程序运行良好。它会出现在屏幕上,还会做祝酒

我正在开发一个应用程序,它可以在所有应用程序的顶部绘制一个窗口。基本上我想做一个像这样的应用。为此,我想开发一款可以在所有应用程序上显示文本视图的应用程序(只是为了测试我的想法)。我是android新手,这是我的第二个应用程序。此外,在学习完udacity android基础课程后,我正在自学

我有一个带有TextView的MainActivity java文件。当用户触摸文本视图时,它将发送到屏幕上的java文件,该文件从服务扩展。到目前为止,我的应用程序运行良好。它会出现在屏幕上,还会做祝酒词。在这一点之后,我有两个问题

  • 在做了祝酒词(这意味着开始屏幕服务类)之后,我不能触摸任何其他应用程序。我用了“FLAG\u NOT\u FOCUSABLE”。在开发者指南中,它可以通过窗口传递触摸事件。但事实并非如此

  • 它不显示文本视图。实际上,我不知道如何在屏幕类中插入它

我的应用程序最低SDK版本是17

Manifest.xml文件

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <service
            android:name=".OnScreen"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

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

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


    </application>

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

</manifest> 

屏幕上的活动

import android.app.Service;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

import static com.prabathhewa.eclips.R.id.dimmer;

public class OnScreen extends Service {
    public OnScreen() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Toast.makeText(getBaseContext(),"onCreate", Toast.LENGTH_LONG).show();

        TextView layout = inflater.inflate(R.layout.on_screen, (ViewGroup) findViewById());

        View myView = new View(this);
        WindowManager.LayoutParams overlay = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,

                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,

                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,

                PixelFormat.TRANSLUCENT);


        overlay.gravity = Gravity.TOP | Gravity.RIGHT;

        WindowManager windowManager = (WindowManager)getSystemService(WINDOW_SERVICE);
        windowManager.addView(myView, overlay);





    }


}
我想显示的带有文本视图的XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/dimmer"
    android:background="#7EFFEB3B"
    tools:context=".OnScreen">

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="On screen"
        android:textSize="40sp"
        android:layout_gravity="center"
        android:textColor="#FF0505"/>

</LinearLayout>
另外,它还帮了我一个忙,就是它还覆盖了通知栏。这里我使用了一个xml文件作为我的视图。定义为

LayoutInflater inflator=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View myView= (View) inflator.inflate(R.layout.on_screen, null);
LayoutInflater inflator=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View myView= (View) inflator.inflate(R.layout.on_screen, null);

但是我不知道如何进入on_screen.xml并获取文本视图。

我通过将layourparams设置为

WindowManager.LayoutParams overlay = new WindowManager.LayoutParams(-1, -1, 2006, 280, -3);
WindowManager.LayoutParams overlay = new WindowManager.LayoutParams(-1, -1, 2006, 280, -3);
另外,它还帮了我一个忙,就是它还覆盖了通知栏。这里我使用了一个xml文件作为我的视图。定义为

LayoutInflater inflator=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View myView= (View) inflator.inflate(R.layout.on_screen, null);
LayoutInflater inflator=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View myView= (View) inflator.inflate(R.layout.on_screen, null);

但是我不知道如何进入on_screen.xml并获取文本视图。

我通过将layourparams设置为

WindowManager.LayoutParams overlay = new WindowManager.LayoutParams(-1, -1, 2006, 280, -3);
WindowManager.LayoutParams overlay = new WindowManager.LayoutParams(-1, -1, 2006, 280, -3);
另外,它还帮了我一个忙,就是它还覆盖了通知栏。这里我使用了一个xml文件作为我的视图。定义为

LayoutInflater inflator=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View myView= (View) inflator.inflate(R.layout.on_screen, null);
LayoutInflater inflator=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View myView= (View) inflator.inflate(R.layout.on_screen, null);
但是我不知道如何进入on_screen.xml并获取文本视图