1.控制NavigationBar显示职位
Navigationbar会随着屏幕的旋转而改变位置,或者在屏幕底部或者是在屏幕一侧,控制的mo默认的位置在PhoneWindowManager 中的navigationBarPosition(...)方法中
private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) {
if (mNavigationBarCanMove && displayWidth > displayHeight) {
if (displayRotation == Surface.ROTATION_270) {
return NAV_BAR_LEFT;
} else {
return NAV_BAR_RIGHT;
}
}
return NAV_BAR_BOTTOM;
可以自行修改,设置默认显示的位置。
2.改变Navigationbar 显示的buttom
修改frameworks/base/packages/SystemUI/res/values-sw600dp/config.xml中的config_navBarLayout值即可进行添加
left;back,home,recent;right
3.扩展navigationbar
3.1首先修改config_navBarLayout的值,加入你要添加的字符串
3.2 修改frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java中的private View createView(String buttonSpec, ViewGroup parent, LayoutInflater inflater) {}方法在里面加入需要的字段判断,引入需要的布局文件(举例引入test.xml)
private View createView(String buttonSpec, ViewGroup parent, LayoutInflater inflater) {
View v = null;
String button = extractButton(buttonSpec);
if (LEFT.equals(button)) {
String s = Dependency.get(TunerService.class).getValue(NAV_BAR_LEFT, NAVSPACE);
button = extractButton(s);
} else if (RIGHT.equals(button)) {
String s = Dependency.get(TunerService.class).getValue(NAV_BAR_RIGHT, MENU_IME);
button = extractButton(s);
}
// Let plugins go first so they can override a standard view if they want.
for (NavBarButtonProvider provider : mPlugins) {
v = provider.createView(buttonSpec, parent);
if (v != null) return v;
}
if (HOME.equals(button)) {
v = inflater.inflate(R.layout.home, parent, false);
} else if (BACK.equals(button)) {
v = inflater.inflate(R.layout.back, parent, false);
} else if (RECENT.equals(button)) {
v = inflater.inflate(R.layout.recent_apps, parent, false);
} else if (Test.equals(button)) {
v = inflater.inflate(R.layout.test, parent, false);
} else if (MENU_IME.equals(button)) {
v = inflater.inflate(R.layout.menu_ime, parent, false);
} else if (NAVSPACE.equals(button)) {
v = inflater.inflate(R.layout.nav_key_space, parent, false);
} else if (CLIPBOARD.equals(button)) {
v = inflater.inflate(R.layout.clipboard, parent, false);
} else if (button.startsWith(KEY)) {
String uri = extractImage(button);
int code = extractKeycode(button);
v = inflater.inflate(R.layout.custom_key, parent, false);
((KeyButtonView) v).setCode(code);
if (uri != null) {
if (uri.contains(":")) {
((KeyButtonView) v).loadAsync(Icon.createWithContentUri(uri));
} else if (uri.contains("/")) {
int index = uri.indexOf('/');
String pkg = uri.substring(0, index);
int id = Integer.parseInt(uri.substring(index + 1));
((KeyButtonView) v).loadAsync(Icon.createWithResource(pkg, id));
}
}
}
return v;
}
4.注意
KeyButtonView.java 中会有private final KeyButtonRipple mRipple; 这个是点击NavigationBar buttom时有一个扩大光圈的效果,注释掉即可取消