Android11修改VolumeUI样式
效果图
改为
vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable-hdpi/ic_volume_mute.png
vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable-hdpi/ic_volume_mute.png
编写VolumeUI的代码
进度条背景
vendor / mediatek / proprietary / packages / apps / SystemUI / res / drawable-hdpi / ic_volume_mute.png
进度条样式
vendor / mediatek / proprietary / packages / apps / SystemUI / res / drawable / my_seekbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 背景 -->
<item android:id="@android:id/background"
android:drawable="@drawable/my_mute">
<shape>
<solid android:color="#fff" />
</shape>
</item>
<!-- 第二进度条 -->
<item android:id="@android:id/secondaryProgress" android:bottom="3dp" android:right="3dp" android:top="3dp" android:left="3dp" >
<clip>
<shape>
<corners android:radius="10dip" />
<gradient
android:startColor="#0144A7"
android:centerColor="#0144A7"
android:centerY="0.75"
android:endColor="#0144A7"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
替换SystemUI中的VolumeUI
/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/volume_dialog_row.xml
去除VolumeUI多余的地方
--- a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
+++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
@@ -219,13 +220,15 @@ public class VolumeDialogImpl implements VolumeDialog,
mWindow.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
mWindow.setWindowAnimations(com.android.internal.R.style.Animation_Toast);
WindowManager.LayoutParams lp = mWindow.getAttributes();
lp.format = PixelFormat.TRANSLUCENT;
lp.setTitle(VolumeDialogImpl.class.getSimpleName());
lp.windowAnimations = -1;
- lp.gravity = mContext.getResources().getInteger(R.integer.volume_dialog_gravity);
+ // lp.gravity = mContext.getResources().getInteger(R.integer.volume_dialog_gravity);
+ //设置位置
+ lp.x = 400;
+ lp.y = 788;
mWindow.setAttributes(lp);
mWindow.setLayout(WRAP_CONTENT, WRAP_CONTENT);
mDialog.setContentView(R.layout.volume_dialog);
mDialogView = mDialog.findViewById(R.id.volume_dialog);
mDialogView.setAlpha(0);
@@ -265,6 +268,7 @@ public class VolumeDialogImpl implements VolumeDialog,
}
mODICaptionsView = mDialog.findViewById(R.id.odi_captions);
+ // 其他不需要view的设置为透明
+ mODICaptionsView.setAlpha(0);
if (mODICaptionsView != null) {
mODICaptionsIcon = mODICaptionsView.findViewById(R.id.odi_captions_icon);
}
@@ -276,6 +280,9 @@ public class VolumeDialogImpl implements VolumeDialog,
mSettingsView = mDialog.findViewById(R.id.settings_container);
mSettingsIcon = mDialog.findViewById(R.id.settings);
+ // 去除不需要的UI
+ mSettingsView.setVisibility(GONE);
+ mSettingsIcon.setVisibility(GONE);
+ mRinger.setVisibility(GONE);
if (mRows.isEmpty()) {
if (!AudioSystem.isSingleVolume(mContext)) {
@@ -283,7 +290,7 @@ public class VolumeDialogImpl implements VolumeDialog,
R.drawable.ic_volume_accessibility, true, false);
}
+ // 替换静音与非静音图标
addRow(AudioManager.STREAM_MUSIC,
- R.drawable.ic_volume_media, R.drawable.ic_volume_media_mute, true, true);
+ R.drawable.ic_volume, R.drawable.ic_volume_mute, true, true);
if (!AudioSystem.isSingleVolume(mContext)) {
addRow(AudioManager.STREAM_RING,
R.drawable.ic_volume_ringer, R.drawable.ic_volume_ringer_mute, true, false);
@@ -405,12 +412,14 @@ public class VolumeDialogImpl implements VolumeDialog,
@SuppressLint("InflateParams")
private void initRow(final VolumeRow row, final int stream, int iconRes, int iconMuteRes,boolean important, boolean defaultStream) {
row.stream = stream;
row.iconRes = iconRes;
row.iconMuteRes = iconMuteRes;
row.important = important;
row.defaultStream = defaultStream;
row.view = mDialog.getLayoutInflater().inflate(R.layout.volume_dialog_row, null);
+ row.view.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
row.view.setId(row.stream);
row.view.setTag(row);
row.header = row.view.findViewById(R.id.volume_row_header);
@@ -419,7 +428,10 @@ public class VolumeDialogImpl implements VolumeDialog,
row.header.setFilters(new InputFilter[] {new InputFilter.LengthFilter(13)});
}
row.dndIcon = row.view.findViewById(R.id.dnd_icon);
row.slider = row.view.findViewById(R.id.volume_row_slider);
+ row.slider.setPadding(0,0,0,0);
row.slider.setOnSeekBarChangeListener(new VolumeSeekBarChangeListener(row));
row.anim = null;
@@ -542,6 +555,7 @@ public class VolumeDialogImpl implements VolumeDialog,
hideCaptionsTooltip();
Events.writeEvent(Events.EVENT_ODI_CAPTIONS_TOOLTIP_CLICK);
});
+ mODICaptionsTooltipView.setAlpha(0);
mODICaptionsTooltipViewStub = null;
rescheduleTimeoutH();
}
@@ -1108,12 +1122,12 @@ public class VolumeDialogImpl implements VolumeDialog,
? Color.alpha(tint.getDefaultColor())
: getAlphaAttr(android.R.attr.secondaryContentAlpha);
if (tint == row.cachedTint) return;
- row.slider.setProgressTintList(tint);
- row.slider.setThumbTintList(tint);
- row.slider.setProgressBackgroundTintList(tint);
- row.slider.setAlpha(((float) alpha) / 255);
- row.icon.setImageTintList(tint);
- row.icon.setImageAlpha(alpha);
+ // 去除音量条轨迹颜色
+ // row.slider.setProgressTintList(tint);
+ // row.slider.setThumbTintList(tint);
+ // row.slider.setProgressBackgroundTintList(tint);
+ // row.slider.setAlpha(((float) alpha) / 255);
+ // row.icon.setImageTintList(tint);
+ // row.icon.setImageAlpha(alpha);
row.cachedTint = tint;
}
去除音量条后白色背景
/ vendor / mediatek / proprietary / packages / apps / SystemUI / res / layout-land / volume_dialog.xml
/ vendor / mediatek / proprietary / packages / apps / SystemUI / res / layout / volume_dialog.xml