安卓,控件置于窗口顶层,控件置顶
Posted Li_water
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安卓,控件置于窗口顶层,控件置顶相关的知识,希望对你有一定的参考价值。
布局文件
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)
以上是关于安卓,控件置于窗口顶层,控件置顶的主要内容,如果未能解决你的问题,请参考以下文章