Android的DISPLY的TextView在屏幕的上方,只要从任何社交媒体或任何邮件或任何形式的EditText的复制的文本社交、文本、屏幕、形式

2023-09-07 01:33:46 作者:再好的网名也败在备注上i

我得到了复制的文本的价值就像从任何信使或邮件或其他社会媒体复制,就像我在信使写你好,我,复制,现在我显示,在吐司消息(以服务所有code所以在背景的作品),它做的,现在我想在屏幕上方显示的TextView此值,每当我从媒体复制的文本,一个TextBox自动运行结束在屏幕的顶部,显示我的复制价值,如何创建这种类型的文本框,就当每一次复制的值,屏幕上方打开?我需要快速的帮助,所以请帮帮我,先谢谢了。

解决方案

您可以做以下到的TextView 添加到屏幕顶部

 窗口管理器窗口管理=(窗口管理器)getSystemService(WINDOW_SERVICE);LayoutInflater吹气=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);TextView的视图=(查看)inflater.inflate(R.layout.activity_main,NULL);view.setText(your_clipboard_text);view.setBackgroundColor(Color.WHITE);WindowManager.LayoutParams PARAMS =新WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.TYPE_PHONE,WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,PixelFormat.TRANSLUCENT);windowManager.addView(视图,则params); 

R.layout.activity_main 是要显示任何布局,你的情况只是一个的TextView 中一个XML

您还需要添加的权限<使用许可权的android:NAME =android.permission.SYSTEM_ALERT_WINDOW/> 在你的清单。

I got the value of the copied text like copied from the any messenger or mail or other social media,like i write in messenger hello,i, copied that now i display that in toast message( all code in service so it works in backgrounds),it done, now i want to display this value in Textview on top of the screen, whenever i copied text from the media ,one textbox automatically opend on top of the screen and display my copied value, how to create this type of textbox,open on top of screen when every time copied value ? i need quick help,so please help me, thanks in advance.

解决方案

You can do the following to add a TextView to the top of the screen

WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

TextView view = (View) inflater.inflate(R.layout.activity_main, null);
view.setText(your_clipboard_text);
view.setBackgroundColor(Color.WHITE);

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

windowManager.addView(view, params);

R.layout.activity_main is any layout that you want to show, in your case just a TextView in an XML

You will also need to add the permission <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> in your manifest.