android- 更改 activity 时隐藏软键(永久)
android- hide softkey (permanently) while changing activity
我的智能手机有软键,我想将其永久隐藏在我的应用程序中。
我使用下面的功能来隐藏软键。
public void setFullscreen(boolean fullscreen) {
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullscreen) {
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
}
else {
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
}
getWindow().setAttributes(attrs);
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
}
我在 onCreate 的所有 activity 中调用该函数,在 protected void onCreate(Bundle savedInstanceState) 之前
像这样..
@Override
protected void onCreate(Bundle savedInstanceState)
{
setFullscreen(true);
super.onCreate(savedInstanceState);
setContentView(R.layout.myLayout);
}
问题:我正在更改 activity 并且软键再次出现和隐藏。我如何防止它们出现?
我还在所有 activity
的清单中使用 "stateHidden"
<activity
android:name=".myActivity"
android:windowSoftInputMode="stateHidden" />
希望您能帮助我...非常感谢! :)
终于!这是一个解决方案。谢谢!
private void hideSystemUI() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
public void setFullscreen(boolean fullscreen) {
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullscreen) {
attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
attrs.flags |= WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN;
}
else {
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
}
getWindow().setAttributes(attrs);
hideSystemUI();
}
我的智能手机有软键,我想将其永久隐藏在我的应用程序中。 我使用下面的功能来隐藏软键。
public void setFullscreen(boolean fullscreen) {
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullscreen) {
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
}
else {
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
}
getWindow().setAttributes(attrs);
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
}
我在 onCreate 的所有 activity 中调用该函数,在 protected void onCreate(Bundle savedInstanceState) 之前 像这样..
@Override
protected void onCreate(Bundle savedInstanceState)
{
setFullscreen(true);
super.onCreate(savedInstanceState);
setContentView(R.layout.myLayout);
}
问题:我正在更改 activity 并且软键再次出现和隐藏。我如何防止它们出现?
我还在所有 activity
的清单中使用 "stateHidden" <activity
android:name=".myActivity"
android:windowSoftInputMode="stateHidden" />
希望您能帮助我...非常感谢! :)
终于!这是一个解决方案。谢谢!
private void hideSystemUI() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
public void setFullscreen(boolean fullscreen) {
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullscreen) {
attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
attrs.flags |= WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN;
}
else {
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
}
getWindow().setAttributes(attrs);
hideSystemUI();
}