Android在退出后隐藏状态栏
因此,我有一个隐藏状态栏的代码,但唯一的问题是,如果我转到主页,然后重新打开应用程序(仍在运行),状态栏就会显示出来。另外,当我按下选项按钮(下面的按钮)时,它会显示状态栏。在重新打开正在运行的应用程序时,是否有方法禁用选项按钮并隐藏状态栏Android在退出后隐藏状态栏,android,user-interface,statusbar,Android,User Interface,Statusbar,因此,我有一个隐藏状态栏的代码,但唯一的问题是,如果我转到主页,然后重新打开应用程序(仍在运行),状态栏就会显示出来。另外,当我按下选项按钮(下面的按钮)时,它会显示状态栏。在重新打开正在运行的应用程序时,是否有方法禁用选项按钮并隐藏状态栏 View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibil
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions)
这是因为当您的活动暂停时,
Statusbar
将可见,因此您需要在活动的onResume
中隐藏Statusbar
,例如:
@Override
protected void onResume() {
super.onResume();
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions)
}
现在,如果您恢复应用程序,它将保持隐藏状态。android清单 选择/将主题设置为
NoActionBar
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
</application>
现在将其从您的MainActivity.java
,
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
在
onCreate
和onResume
方法中隐藏通知栏对我来说很有用:
public override fun onCreate(
savedInstanceState: Bundle?
) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Hide the status bar
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
}
public override fun onResume() {
super.onResume()
// Hide the status bar
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
}
没有标题栏,那是做什么的?还有,它说没有操作栏?它解决了选项卡没有显示的问题,但当我多次按下选项按钮时,状态栏显示出来。您是否已从活动中删除了创建选项菜单的
oncreateoptions
。如果我在第一个开口处按两下,就会显示出来。但后来,它被修复了。唯一的问题是,如果我在打开应用程序后按了两次。请从菜单文件夹中删除menu.xml噢,谢谢:)。我还有一个问题。当我按下手机上的选项按钮时,状态栏就会显示出来。有没有办法禁用手机底部的选项按钮?你说的是家附近的选项按钮和底部的后退按钮?哦,是的。我刚刚意识到,当我尝试重新打开应用程序时。对于选项按钮问题,请尝试我的解决方案。哦,我的意思是,我只是不希望选项按钮显示类似于显示“设置”选项卡和状态栏的内容。我以后再试试。:)很抱歉,它没用。当我按下选项按钮时,状态栏显示出来,设置选项卡也显示出来。