我正在開發應用程序,我需要禁用應用程序開始運行時的虛擬按鈕,因爲應用程序中有按鈕。任何人都可以幫助我如何編碼?先謝謝你。當應用程序運行時禁用Android設備的按鈕
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_1st_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private final List hijackKeys = new ArrayList(Arrays.asList(
KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP,
KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_HOME));
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (hijackKeys.contains(event.getKeyCode())) {
return true;
} else {
return super.dispatchKeyEvent(event);
}
}
,您可以隱藏4.0導航條(未禁用,只是隱藏),請參閱[developer.android.com/navigation](https://developer.android.com/training/system-ui/ navigation.html) – hypd09
你可以通過覆蓋禁用後退按鈕和菜單按鈕,但你不能禁用主頁按鈕.... –
嗨@ hypd09,感謝您的迴應!但是,您提到的代碼不起作用。 – androidBoomer