我在WindowManager.LayoutParams.TYPE_TOAST级别层上有一个带按钮的覆盖视图。 该按钮在Android 4.2中可以正常工作,但是当我在Android 4.3中运行相同的代码时,该按钮将变得不可单击-单击该按钮时不会发生任何反应。
这是相关的代码。
ButtonOverlayService.java
@Override
public IBinder onBind(Intent intent) {
return null;
}
public class ButtonOverlayService extends Service {
WindowManager wm;
View home_button_view;
@Override
public void onCreate() {
super.onCreate();
WindowManager.LayoutParams home_params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
-10000,
10000,
WindowManager.LayoutParams.TYPE_TOAST,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
LayoutInflater layoutInflater = LayoutInflater.from(this);
home_button_view = layoutInflater.inflate(R.layout.home_button_overlay, null);
home_button_view.findViewById(R.id.home_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.i("myApp", "clicked")
}
}
wm.addView(home_button_view, home_params);
}
}
home_button_overlay.xml
android:id="@+id/home_button"
android:layout_width="100dp"
android:layout_height="100dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#85ff3f"
android:padding="0dp"
android:paddingEnd="0dp"
android:paddingStart="0dp"
android:gravity="fill">
有人知道吗