安卓开发者进来一下,安卓悬浮窗口开发有问,悬浮的EditText为啥无法获得焦点.悬浮窗口不管我

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安卓开发者进来一下,安卓悬浮窗口开发有问,悬浮的EditText为啥无法获得焦点.悬浮窗口不管我相关的知识,希望对你有一定的参考价值。

安卓开发者进来一下,安卓悬浮窗口开发有问,悬浮的EditText为什么无法获得焦点.悬浮窗口不管我怎么设置type属性,强制弹出输入框等都无法实现悬浮的EditText获得焦点,有些窗口属性只能实现能获得焦点能输入但不能移动悬浮窗不可触摸等等问题,无法获得焦点也就是说悬浮的EditText无法弹出输入法输入文字,但可长按粘贴东西进去,但是悬浮的Button、Textview等都能获得焦点.支持点击事件,为什么EditText就不能弹出输入法?求大神们帮忙解决这个问题,有什么方法让悬浮的EditText能输入文字

悬浮窗不支持输入的,本身有很多限制的,还有不能全屏等等,很多,如果要实现输入,最好还是开一个activity,哪怕是透明的也行,一般的做法就是点击输入框直接弹出半透明页面,在这里面的输入框中输入追问

原来是这样,那就是没办法了,唉,自己再挖掘挖掘

参考技术A 打谷歌的客服反应,谷歌的开发人员不会上百度追问

额,不懂安卓开发不要乱说...

追答

安卓是谷歌公司开发的,ui才是其他人加上去的,你要说说你用的什么ui,然后找做ui的人优化

追问

额,我就是个安卓开发者.我去找谷歌做UI设计干嘛...

安卓开发多个或俩个悬浮球一起悬浮窗

1. 主页面的设置,开启权限
//启动 计算器悬浮框 服务, 用于快速调出计算器。
public void startFloatingButtonService()
if (FloatingButtonService.isStarted)
return;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
if (!Settings.canDrawOverlays(this))
// ToastUtils.showShort( “当前无权限,请授权”);
Toast.makeText(this, “当前无权限,请授权”, Toast.LENGTH_SHORT).show();
startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse(“package:” + getPackageName())), 0);
else
startService(new Intent(MainActivity.this, FloatingButtonService.class));


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    if (requestCode == 0) 
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 
            if (!Settings.canDrawOverlays(this)) 
                Toast.makeText(this, "权限获取失败! 计算器悬浮窗口将不可用", Toast.LENGTH_SHORT).show();
            else 
                // Toast.makeText(this, "授权成功", Toast.LENGTH_SHORT).show();
                startService(new Intent(MainActivity.this, FloatingButtonService.class));
            
        
    

  1. 在AndroidManifest定义权限
    在 application 里加
    加下面这句话service


    3. 创一个FloatingButtonService extends Service 这里开始设置悬浮窗大小什么的
    public class FloatingButtonService extends Service
    public static boolean isStarted = false;
    int downTime ;//Button被按下时的时间
    int thisTime ;//while每次循环时的时间
    boolean onBtnTouch = false;//Button是否被按下
    private WindowManager windowManager;
    private WindowManager.LayoutParams layoutParams;
    private Context context;
    private ImageView imageView,imageView1;
    LinearLayout mFloatLayout,layout1;
    @Override
    public void onCreate()
    super.onCreate();
    context = this;
    isStarted = true;
    windowManager = (WindowManager) getApplicationContext().getSystemService(getApplicationContext().WINDOW_SERVICE);
    layoutParams = new WindowManager.LayoutParams();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
    layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    else
    layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;

    layoutParams.format = PixelFormat.RGBA_8888;
    layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
    layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    layoutParams.width = 80;
    layoutParams.height = 160;
    layoutParams.x = 1200-layoutParams.width;
    layoutParams.y = 300;

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

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    showFloatingWindow();

    return super.onStartCommand(intent, flags, startId);

    private void showFloatingWindow()
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    if (Settings.canDrawOverlays(this))
    layout1=new LinearLayout(getApplicationContext());
    //获取布局界面
    LayoutInflater inflater=LayoutInflater.from(getApplicationContext());
    mFloatLayout=(LinearLayout)inflater.inflate(R.layout.layout,null,false);
    layout1.addView(mFloatLayout);
    imageView = (ImageView) mFloatLayout.findViewById(R.id.close);
    imageView1 = (ImageView) mFloatLayout.findViewById(R.id.back);
    windowManager.addView(layout1,layoutParams);
    layout1.setOnTouchListener(new FloatingOnTouchListener());

            imageView.setOnTouchListener(new View.OnTouchListener() 
                @Override
                public boolean onTouch(View v, MotionEvent event) 
    
                    if (thisTime-downTime<2)
                       Intent intent = new Intent(FloatingButtonService.this, Main2Activity.class);
                       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                       startActivity(intent);
                
                 return false;
               
            );
        
    
    
    


    //设置点击 移动 松开等事件
    private class FloatingOnTouchListener implements View.OnTouchListener
    private int x;
    private int y;

    @Override
    public boolean onTouch(View view, MotionEvent event) 
        switch (event.getAction()) 
            case MotionEvent.ACTION_DOWN:
           // 悬浮球被按下时操作
                x = (int) event.getRawX();
                y = (int) event.getRawY();
                Calendar calendar = Calendar.getInstance();
                downTime = calendar.get(Calendar.SECOND);
                Toast.makeText(getApplicationContext(), downTime + ":" + "按下", Toast.LENGTH_SHORT).show();
                break;
            case MotionEvent.ACTION_MOVE:
            //移动时
                int nowX = (int) event.getRawX();
                int nowY = (int) event.getRawY();
                int movedX = nowX - x;
                int movedY = nowY - y;
                x = nowX;
                y = nowY;
                layoutParams.x = layoutParams.x + movedX;
                layoutParams.y = layoutParams.y + movedY;
                windowManager.updateViewLayout(view, layoutParams);
                break;
            default:
                break;
            case MotionEvent.ACTION_UP:
          //  结束时松开后
                Calendar calendar1 = Calendar.getInstance();
                thisTime = calendar1.get(Calendar.SECOND);
                Toast.makeText(getApplicationContext(), thisTime + ":" + "抬起", Toast.LENGTH_SHORT).show();
                break;
        
        return false;
    
    


4. layout布局

以上是关于安卓开发者进来一下,安卓悬浮窗口开发有问,悬浮的EditText为啥无法获得焦点.悬浮窗口不管我的主要内容,如果未能解决你的问题,请参考以下文章

安卓开发多个或俩个悬浮球一起悬浮窗

安卓悬浮球源代码(长按判断多次点击判断自动贴边)

JS悬浮窗口如何实现

让安卓手机秒变iphone的神器,来了!!

安卓手机开启无障碍功能与悬浮窗的方法

vue解决安卓手机软键盘弹出,页面高度被顶起