可能重複:
Android 1.6: 「android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application」安卓:無法添加窗口 - 令牌null不是一個應用程序
android.view.WindowManager $ BadTokenException:無法添加窗口 - - 標記null不適用於android.view.ViewRoot.setView(ViewRoot.java:509) 處的應用程序 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) 在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
我的代碼:
public class aaaa extends View {
private WindowManager mWindowManager;
public aaaa(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon), 0, 0, null);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
ddd();
return super.onTouchEvent(event);
}
void ddd(){
mWindowManager = WindowManagerImpl.getDefault();
WindowManager.LayoutParams lp = new LayoutParams(50,50);
lp.x = 50;
lp.y = 50;
mWindowManager.addView(this, lp);
}
一個更深入的解釋和更好的標題,你實際上會問什麼 – ninjasense 2010-12-20 06:59:21