安卓,控件置于窗口顶层,控件置顶

布局文件

imgview_home.xml
~~-~~ 
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/home_home_top"
    android:background="#50E911"
    android:layout_width="50dp"
    android:layout_height="50dp"/>
main
~~--~~ 
  WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                0, 0,
                PixelFormat.TRANSPARENT
        );
        //这句话会阻止软键盘弹出,换成  layoutParams.flags= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;就好了。
        layoutParams.flags= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
// type 设置 Window 类别(层级)
   layoutParams.type = WindowManager.LayoutParams.TYPE_TOAST;
   //位置
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.gravity = Gravity.BOTTOM;
        //边距
        layoutParams.y = 25;
        View view3 = LayoutInflater.from(this).inflate(R.layout.imgview_home,null);
        ImageView imageView = view3.findViewById(R.id.home_home_top);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
			            Toast.makeText(this,"回到主页",Toast.LENGTH_LONG).show();
			            //home键方法
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addCategory(Intent.CATEGORY_HOME);
                startActivity(intent);

            }
        });
        WindowManager windowManager = this.getWindowManager();
        try {
            windowManager.addView(imageView,layoutParams);
        }catch (Exception p){}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值