这是我添加视图的代码:
LayoutInflater layoutInflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView tv = (TextView) layoutInflater.inflate(R.layout.textview, null);
final View view = tv;
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, 25,
WindowManager.LayoutParams.TYPE_STATUS_BAR,
WindowManager.LayoutParams.FLAG_SCALED
, PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);
wm.addView(view, lp);
但这会给我一个错误:
android.view.WindowManager$BadTokenException: 无法添加窗口 android.view.ViewRootImpl$W@41668948 -- 此窗口类型的权限被拒绝
所以我在android manifast中添加了权限
<uses-permission android:name="android.permission.STATUS_BAR" />
但仍然有错误,我需要帮助!