如何在Android中隐藏状态栏
我提到这个链接 。 在这种情况下,如果用户点击EditText(对于ex:),那么键盘将popup,同时用户可以滚动查看所有剩余的视图(例如:撰写,主题,发送button)那个屏幕。 同样在我的应用程序,我有一个活动,我有一些小部件或意见。 假设如果用户点击我的Activity中的Edittext,那么键盘popup,我可以滚动查看剩余的视图。 但如果我给这个属性android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
在清单我无法滚动查看剩余的意见,但如果给属性android:theme="@android:style/Theme.NoTitleBar"
像这样在清单中,我可以滚动查看剩余的视图,但在屏幕上有状态栏,在这里我想全屏,即使键盘popup我可以滚动查看剩余的意见..? 我必须做出什么改变..?
写在你的活动
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); }
和你的应用程序将全屏。 没有状态栏,没有标题栏。 🙂
if (Build.VERSION.SDK_INT < 16) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); ActionBar actionBar = getActionBar(); actionBar.hide(); }
使用主题"Theme.NoTitleBar.Fullscreen"
并尝试为AndroidManifest.xml.
的活动设置"android:windowSoftInputMode=adjustResize"
AndroidManifest.xml.
你可以在这里find细节。
这应该隐藏Android中的状态:
requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
如果你在一个活动中需要这个,你必须在setContentView之前放置onCreate:
requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.your_screen);
在manifest.xml文件中更改应用程序的主题。
android:theme="@android:style/Theme.Translucent.NoTitleBar"
将此用于您的Activity
。
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); }
void hideStatusBar() { if (Build.VERSION.SDK_INT < 16) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); } } You can use this method to hide the status bar. And this is important to hide the action bar too. In this case, you can **getSupportActionBar().hide()** if you have extended the activity from support lib like Appcompat or you can simply call **getActionBar().hide()** after the method mentioned above. Thanks
(4.4+)kitkat或以上的设备,我们无法阻止全屏模式下出现的状态,所以尝试黑客阻止状态栏展开。
解决scheme很大,所以这里是SO的链接:
StackOverflow:隐藏状态栏在Android 4.4 +或全屏幕与kitkat
这段代码隐藏了状态栏。
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
隐藏操作栏写下这一行: –
requestWindowFeature(Window.FEATURE_NO_TITLE);
两行可以共同编写,以隐藏操作栏和状态栏。 所有这些行必须在onCreate
方法中的setContentView
方法调用之前写入。
这是关于在Android 4.0及更低版本以及Android 4.1及更高版本上隐藏状态栏的官方文档
请看看它:
https://developer.android.com/training/system-ui/status.html
使用此代码:
requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.youractivityxmlname);
添加你的Activity类
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); // some your code }
这个解决scheme对我来说:)
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= 19) { getWindow().setFlags(AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT, AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT); getWindow().getDecorView().setSystemUiVisibility(3328); }else{ requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); } DataBindingUtil.setContentView(this, R.layout.activity_hse_video_details);
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // If the Android version is lower than Jellybean, use this call to hide // the status bar. if (Build.VERSION.SDK_INT < 16) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { View decorView = getWindow().getDecorView(); // Hide the status bar. int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); // Remember that you should never show the action bar if the // status bar is hidden, so hide that too if necessary. ActionBar actionBar = getActionBar(); actionBar.hide(); } setContentView(R.layout.activity_main); } ... }