1. Fügen Sie zunächst in den Einstellungen ein Menü als Schalter zum Ausblenden der Navigationsleiste hinzu.
Definieren Sie die Zeichenfolge packets/apps/Settings/res/values/strings.xml
<string name="ctrl_navigationbar">Hide NavigationBar</string>
Fügen Sie den Menüpunkt packets/apps/Settings/res/xml/display_settings.xml hinzu
<SwitchPreference
android:key="ctrl_navigationbar"
android:title="@string/ctrl_navigationbar"/>
Fügen Sie die entsprechenden Controller-Listenpakete/apps/Settings/src/com/android/settings/DisplaySettings.java hinzu
controllers.add(new NavigationBarPreferenceController(context));
Controller hinzufügen
packets/apps/Settings/src/com/android/settings/display/NavigationBarPreferenceController.java
package com.android.settings.display;
import android.content.Context;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import android.content.Intent;
import android.util.Log;
import android.os.SystemProperties;
public class NavigationBarPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
private static final String TAG = "NavigationBarCtrl";
private static final boolean DEBUG = true;
private static final String KEY_NAVIGATION_BAR = "ctrl_navigationbar";
public static final String ACTION_HIDE_NAVIGATION_BAR = "com.systemui.navigationbar.hide";
public static final String ACTION_SHOW_NAVIGATION_BAR = "com.systemui.navigationbar.show";
public NavigationBarPreferenceController(Context context) {
super(context);
}
@Override
public String getPreferenceKey() {
return KEY_NAVIGATION_BAR;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public void displayPreference(PreferenceScreen screen) {
if (!isAvailable()) {
setVisible(screen, KEY_NAVIGATION_BAR, false /* visible */);
return;
}
final SwitchPreference mNavigationBarPreference = (SwitchPreference)screen.findPreference(KEY_NAVIGATION_BAR);
if (mNavigationBarPreference != null) {
String value = SystemProperties.get("persist.sys.navigationbar.enable", "false");
mNavigationBarPreference.setChecked(value.equals("true"));
mNavigationBarPreference.setOnPreferenceChangeListener(this);
}
}
@Override
public void updateState(Preference preference) {
String value = SystemProperties.get("persist.sys.navigationbar.enable", "false");
((SwitchPreference) preference).setChecked(value.equals("true"));
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
if (DEBUG) {
Log.d(TAG, "key value " + value);
}
Intent intent = new Intent();
if (value) {
intent.setAction(ACTION_SHOW_NAVIGATION_BAR);
} else {
intent.setAction(ACTION_HIDE_NAVIGATION_BAR);
}
mContext.sendBroadcast(intent);
return true;
}
}
2. Ändern Sie SystemUi
Frameworks/base/packages/SystemUI/AndroidManifest.xml
<!-- For NavigationBar show or not -->
<protected-broadcast android:name="com.systemui.navigationbar.show" />
<protected-broadcast android:name="com.systemui.navigationbar.hide" />
Definieren Sie Broadcasts und entsprechende Systemeigenschaften
private static final String ACTION_HIDE_NAVIGATION_BAR = "com.systemui.navigationbar.hide";
private static final String ACTION_SHOW_NAVIGATION_BAR = "com.systemui.navigationbar.show";
private static final String SYS_PROPERTY_NAVIGATION_BAR = "persist.sys.navigationbar.enable";
Bestimmen Sie in der Startmethode den Attributwert und ob die Statusleiste geladen werden soll
if (!SystemProperties.getBoolean(SYS_PROPERTY_NAVIGATION_BAR, false)) {
mStatusBarWindow.setVisibility(View.GONE);
}
Bestimmen Sie, ob die Navigationsleiste in der Methode makeStatusBarView geladen werden soll
if (SystemProperties.getBoolean(SYS_PROPERTY_NAVIGATION_BAR, false)) {
createNavigationBar();
}
Der Rundfunkempfänger übernimmt die entsprechende Logik
else if (ACTION_HIDE_NAVIGATION_BAR.equals(action)) {
mWindowManager.removeViewImmediate(mNavigationBarView);
mNavigationBarView = null;
mStatusBarWindow.setVisibility(View.GONE);
SystemProperties.set(SYS_PROPERTY_NAVIGATION_BAR, "false");
} else if (ACTION_SHOW_NAVIGATION_BAR.equals(action)) {
if(mNavigationBarView == null)
createNavigationBar();
else
mNavigationBarView.setVisibility(View.VISIBLE);
mStatusBarWindow.setVisibility(View.VISIBLE);
SystemProperties.set(SYS_PROPERTY_NAVIGATION_BAR, "true");
}