取色器
ColorPix自定義對(duì)話框報(bào)異常:
The specified child already has a parent. You must call removeView()
在AlertDialog.Builder(mContext).setView(view)
中,子視圖是view
,父視圖是Builder
氏淑,按下面文章所說(shuō)的疮胖,原因就是:一個(gè)子視圖指定了多個(gè)父視圖勤众。由此可以推斷出屹电,在第二次點(diǎn)擊按鈕彈出對(duì)話框時(shí)懂傀,子視圖與第一次點(diǎn)擊時(shí)的子視圖是同一個(gè)對(duì)象兄裂,而父視圖已經(jīng)不再是同一個(gè)對(duì)象了脑慧。Android使用自定義對(duì)話框報(bào)錯(cuò):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。
- 沉浸式狀態(tài)欄
首先給Activity根布局設(shè)置屬性:android:fitsSystemWindows="true"
然后調(diào)用下面的方法:
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
請(qǐng)看項(xiàng)目https://github.com/jgilfelt/SystemBarTint