取色器
ColorPix自定義對話框報異常:
The specified child already has a parent. You must call removeView()
在AlertDialog.Builder(mContext).setView(view)
中,子視圖是view
,父視圖是Builder
,按下面文章所說的,原因就是:一個子視圖指定了多個父視圖。由此可以推斷出,在第二次點擊按鈕彈出對話框時,子視圖與第一次點擊時的子視圖是同一個對象,而父視圖已經不再是同一個對象了。Android使用自定義對話框報錯:The specified child already has a parent. You must call removeView() on the...
解決辦法:
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null) {
parent.removeAllViews();
}
然后再給AlertDialog指定view。
- 沉浸式狀態欄
首先給Activity根布局設置屬性:android:fitsSystemWindows="true"
然后調用下面的方法:
protected void setTranslucentStatus(int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(color);// 通知欄所需顏色
}
@TargetApi(19)
private void setTranslucentStatus(boolean on) {
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if (on) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
}
win.setAttributes(winParams);
}
其中類SystemBarTintManager
請看項目https://github.com/jgilfelt/SystemBarTint