现象
状态栏图标显示的个数有两个限制:
1.最大个数限制8个(包括battery):
2.宽度限制;
最终能够显示的图标个数取这两个限制的较小值。
相关代码逻辑在com.android.systemui.statusbar.phone/StatusIconContainer.java类中:
// Max 8 status icons including battery
private static final int MAX_ICONS = 7;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
mMeasureViews.clear();
int mode = MeasureSpec.getMode(widthMeasureSpec);
final int width = MeasureSpec.getSize(widthMeasureSpec);
final int count = getChildCount();
// Collect all of the views which want to be laid out
for (int i = 0; i < count; i++) {
StatusIconDisplayable icon = (StatusIconDisplayable) getChildAt(i);
if (icon.isIconVisible() && !icon.isIconBlocked()) {
mMeasureViews.add((View) icon);
}
}
int visibleCount = mMeasureViews.size();
int maxVisible = visibleCount <= MAX_ICONS ? MAX_ICONS : MAX_ICONS - 1;
int totalWidth = mPaddingLeft + mPaddingRight;
boolean trackWidth = true;
// Measure all children so that they report the correct width
int childWidthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.UNSPECIFIED);
mNeedsUnderflow = mShouldRestrictIcons && visibleCount > MAX_ICONS;
for (int i = 0; i < mMeasureViews.size(); i++) {
// Walking backwards
View child = mMeasureViews.get(visibleCount - i - 1);