本文是基於Android5.1的代碼
frameworks\base\packages\SystemUI\src\com\android\systemui\volume\VolumePanel.java
private void createSliders() {
final Resources res = mContext.getResources();
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
mStreamControls = new SparseArray<StreamControl>(STREAMS.length);
final StreamResources notificationStream = StreamResources.NotificationStream;
for (int i = 0; i < STREAMS.length; i++) {
StreamResources streamRes = STREAMS[i];
final int streamType = streamRes.streamType;
final boolean isNotification = isNotificationOrRing(streamType);
final StreamControl sc = new StreamControl();
sc.streamType = streamType;
sc.group = (ViewGroup) inflater.inflate(
com.android.systemui.R.layout.volume_panel_item, null);
sc.group.setTag(sc);
sc.icon = (ImageView) sc.group.findViewById(com.android.systemui.R.id.stream_icon);
sc.icon.setTag(sc);
sc.icon.setContentDescription(res.getString(streamRes.descRes));
sc.iconRes = streamRes.iconRes;
sc.iconMuteRes = streamRes.iconMuteRes;
sc.icon.setImageResource(sc.iconRes);
sc.icon.setClickable(isNotification && mHasVibrator);
if (isNotification) {
if (mHasVibrator) {
sc.icon.setSoundEffectsEnabled(false);
sc.iconMuteRes = com.android.systemui.R.drawable.ic_ringer_vibrate;
sc.icon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
resetTimeout();
toggleRinger(sc);
}
});
}
sc.iconSuppressedRes = com.android.systemui.R.drawable.ic_ringer_mute;
}
sc.seekbarView = (SeekBar) sc.group.findViewById(com.android.systemui.R.id.seekbar);
sc.suppressorView =
(TextView) sc.group.findViewById(com.android.systemui.R.id.suppressor);
sc.suppressorView.setVisibility(View.GONE);
final boolean showSecondary = false; //!isNotification && notificationStream.show;
sc.divider = sc.group.findViewById(com.android.systemui.R.id.divider);
sc.secondaryIcon = (ImageView) sc.group
.findViewById(com.android.systemui.R.id.secondary_icon);
sc.secondaryIcon.setImageResource(com.android.systemui.R.drawable.ic_ringer_audible);
sc.secondaryIcon.setContentDescription(res.getString(notificationStream.descRes));
sc.secondaryIcon.setClickable(showSecondary);
sc.divider.setVisibility(showSecondary ? View.VISIBLE : View.GONE);
sc.secondaryIcon.setVisibility(showSecondary ? View.VISIBLE : View.GONE);
if (showSecondary) {
sc.secondaryIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSecondaryIconTransition.start(sc);
}
});
}
final int plusOne = (streamType == AudioSystem.STREAM_BLUETOOTH_SCO ||
streamType == AudioSystem.STREAM_VOICE_CALL) ? 1 : 0;
sc.seekbarView.setMax(getStreamMaxVolume(streamType) + plusOne);
sc.seekbarView.setOnSeekBarChangeListener(mSeekListener);
sc.seekbarView.setTag(sc);
mStreamControls.put(streamType, sc);
}
}
final boolean showSecondary = false 即可,具體的代碼熟知這裏不再做過多廢話!