请任何人都可以帮助我,我正在开发应用程序:当有人打电话给你时,会显示一个包含一些信息的布局,在那个布局中,当我点击它时,关闭一个按钮,它应该隐藏布局或破坏应用程序,我的问题是布局显示但按钮是不可点击的,它就像按钮的图像。这是我的代码:
@Override
public void onCreate() {
super.onCreate();
toastLayout = (ViewGroup)layoutInflater.inflate(R.layout.toast, null);
defaultPopupHorizontalGravity = getResources().getInteger(R.integer.default_popup_horizontal_gravity);
defaultPopupVerticalGravity = getResources().getInteger(R.integer.default_popup_vertical_gravity);
//defaultPopupMap = Boolean.parseBoolean(getResources().getString(R.string.default_popup_map));
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE//FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,//FLAG_NOT_TOUCHABLE
PixelFormat.TRANSLUCENT
);
Button X = (Button) toastLayout.getChildAt(0);
toastLayout.addView(X);
X.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("Clicked----><<<<<<<");
}
});
X.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
System.out.println("Touched =----- > ");
return false;
}
});
windowManager.addView(toastLayout, params);
答案 0 :(得分:0)
您正在使用FLAG_NOT_TOUCH_MODAL
和FLAG_NOT_FOCUSABLE
来禁用布局的触摸,因为它是使用这些参数创建的
您也不需要再次添加按钮X,因为它已经是您的吐司布局的子项(否则getChildAt
将无法按预期工作,并且如果该位置的孩子可能会产生转换异常不是按钮)所以删除行:
toastLayout.addView(X);