如何在Activity的顶层添加View

1.这种一般没什么问题,但是还是不够顶

getWindow().getDecorView()

2.在本Activity里添加View,没问题,不要添加全局View

 TextView textView = new TextView(getBaseContext());
        textView.setText("this is title");
        textView.setTextColor(Color.RED);
        textView.setWidth(200);
        textView.setHeight(200);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,170);
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
        WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        windowManager.addView(textView, layoutParams);

你可能感兴趣的:(android)