基于MTK8163 8.1平台定制导航栏部分,在左边增加音量减,右边增加音量加
增加需要的音量资源文件,增加4张图片到drawable图片资源下,注意尺寸和back,home,recent一致,分为亮色和暗色两种图片。(图片尽然还要自己搞,幸好有在线PS可以修改尺寸和颜色)
ic_sysbar_volume_up.png,ic_sysbar_volume_up_dark.png,ic_sysbar_volume_down.png,ic_sysbar_volume_down_dark.png;
layout下增加volume_down.xml 和 volume_up.xml(里面keyRepeatExt是自己定义的,可以忽略,为了标识是音量键,方便在KeyButtonView.java里作特殊长按处理)
left;volume_down,back,home,recent,volume_up;right
90dp
0dp
public static final String VOLUME_DOWN = "volume_down";
public static final String VOLUME_UP = "volume_up";
createView()方法里增加 ,以加载音量加减的布局:
else if (VOLUME_DOWN.equals(button)) {
v = inflater.inflate(R.layout.volume_down, parent, false);
} else if (VOLUME_UP.equals(button)) {
v = inflater.inflate(R.layout.volume_up, parent, false);
}
private KeyButtonDrawable mVolumeDown,mVolumeUp;
构造方法里增加,put到mButtonDispatchers数据结构里:
mButtonDispatchers.put(R.id.volume_down, new ButtonDispatcher(R.id.volume_down));
mButtonDispatchers.put(R.id.volume_up, new ButtonDispatcher(R.id.volume_up));
getVolumeDownButton().setLongClickable(false);
getVolumeUpButton().setLongClickable(false);
增加新方法:
public ButtonDispatcher getVolumeDownButton() {
return mButtonDispatchers.get(R.id.volume_down);
}
public ButtonDispatcher getVolumeUpButton() {
return mButtonDispatchers.get(R.id.volume_up);
}
updateIcons()方法里增加,获取音量加减的icon资源:
mVolumeDown = getDrawable(ctx,R.drawable.ic_sysbar_volume_down,R.drawable.ic_sysbar_volume_down_dark);
mVolumeUp = getDrawable(ctx,R.drawable.ic_sysbar_volume_up,R.drawable.ic_sysbar_volume_up_dark);
调用方法setNavigationIconHints()里增加对音量图片资源的设置:
getVolumeDownButton().setImageDrawable(mVolumeDown);
getVolumeUpButton().setImageDrawable(mVolumeUp);
setDisabledFlags()方法里增加:
//volume down and up just follow the home key
getVolumeDownButton().setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE);
getVolumeUpButton().setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE);
至此,make,push…