Android make activity fullscreen

Полноэкранная активность в Android?

Как сделать активность в полноэкранном режиме? Я имею в виду без панели уведомлений. Есть идеи?

25 ответов:

вы можете сделать это программно:

или вы можете сделать это через свой AndroidManifest.xml file:

Edit:

если вы используете AppCompatActivity, то вам нужно установить тему, как показано ниже

есть техника под названием Захватывающий Полноэкранный Режим в наличии KitKat.

если вы не хотите использовать тему @android:style/Theme.NoTitleBar.Fullscreen потому что вы уже используете собственную тему, вы можете использовать android:windowFullscreen .

на AndroidManifest.xml file:

или Java код:

Если вы используете AppCompat и ActionBarActivity, то используйте это

Если вы используете какой-либо метод, чтобы установить панель действий следующим образом:

это вызовет исключение нулевого указателя.

попробуйте это с appcompat от style.xml . Он может поддерживать все платформы.

Примечание: В моем случае я должен был использовать name=»windowActionBar» вместо name=»android:windowActionBar» прежде чем он нормально работал. Поэтому я просто использовал оба, чтобы убедиться, что в случае, если мне нужно перенести на новую версию Android позже.

I. ваша главная тема приложения —тема.Совместимости приложений.Свет.DarkActionBar

для скрытия ActionBar / StatusBar
стиль.xml

для скрыть панель навигации системы

второй. Ваша главная тема приложение тема.Совместимости приложений.Свет.NoActionBar

для скрытия панели действий / Строка состояния
стиль.xml

для скрыть панель навигации системы

как как Theme.AppCompat.Light.DarkActionBar .

совет: использование getWindow ().setLayout() может испортить ваш полноэкранный дисплей! Примечание в документации на этот метод говорит:

установите параметры макета ширины и высоты окна. вы можете изменить их . абсолютное значение для создания окна, которое не является полноэкранным.

для моих целей, я обнаружил, что я должен был использовать setLayout с абсолютными параметрами для правильного изменения размера моего полноэкранного окна. Большую часть времени, это работало нормально. Он был вызван событием onConfigurationChanged (). Однако тут возникла икота. Если пользователь вышел из приложения, изменил ориентацию и вернулся, это приведет к запуску моего кода, который включал setLayout(). Во время этого окна времени повторного входа моя строка состояния (которая была скрыта манифестом) будет повторно отображаться, но в любое другое время setLayout() не вызовет этого! Решение состояло в том, чтобы добавить дополнительный вызов setLayout () после одного с жесткими значениями, такими как:

Читайте также:  Android для hyundai ix35

затем окно было правильно изменено, и строка состояния не появлялась снова независимо от события, которое вызвало это.

Источник

BragitOff.com

READ-LEARN-BRAG!

How to make a particular Activity Fullscreen? [Solution] (Android Development)

Making an Activity Fullscreen is not very tough.

But the question is what exactly you want to do. Do you have an app which has an actionbar(toolbar or title bar)
and you just want a particular activity to not display the actionbar(toolbar) ? like this:

BEFORE: with actionbar AFTER: without actionbar

Or do you want your Activity to be completely Fullscreen(called immersive) such that it covers/hides the status bar(notification bar where you see the battery and stuff) or navigation bar? like this:

The solution to the former question: that is, to hide the actionbar follow the following steps:

  • Open your AndroidManifest.xml file and add the following code to the activity that you want to be displayed wihout the actionbar:

So that your activity looks like this:

However, the above code may not always work depending on the theme you are using.
So basically what you need to do is add a theme without an action bar to the activity code.
So just try typing ‘No’ inside the theme as shown and wait for the Android Studio or whatever IDE you are using to suggest a theme suitable for you.

If the above method to hide the actionbar did not work for you then don’t worry, I show another way to hide the action bar later on in the article. That method is using JAVA.

  • However, to make your app completely Fullscreen such that it even hides the status bar follow the following steps:
Читайте также:  Системные мелодии от андроид

For Android 4.0(API level 14) and lower:
The official article by google suggests to add the following code to the app’s mainfest file:

where ‘Holo’ is the theme name. Note: It may be different for your case.
But it didn’t work for me as the above code threw an error when I tried it. So I am not sure about this method.

For Android 4.1(API level 16) or higher:

You can hide the status bar on devices running Android 4.1 or higher by adding the following code to the activity’s OnCreate Method:

You can even hide the actionbar by adding the following snippet to the OnCreate Method of your Activity:

So now I’ve shown you two ways to hide the Action Bar for your activity.

NOTE: Though the above method hides the status bar, it is not perfect and probably not what you wanted .

Why do I say that?
It’s cause when I tested this method on my Sony Xperia C running Jelly Bean the status bar was hidden permanently.
Meaning that the user had no way of accessing the status bar once the activity went full-screen.
Though what I expected or rather wanted was to have the status bar hidden but in a way such that the user could access the status bar by swiping downwards and then when they swiped up the status bar should disappear(hide).

On another device running Android 5 (API Level 21 or 22 ,Lollipop) I noticed that the user could access the status bar by swiping downwards but once it was accessed it never disappeared.

Читайте также:  Процесс com android phone остановлен что это значит

Fix:

In this Official Article by Google they have provided a way to provide the users with Android 4.4(API level 19), with a fully immersive experience by using SYSTEM_UI_FLAG_IMMERSIVE flags.

When you use the SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag, an inward swipe in the status bar(notification) areas causes the bars to temporarily appear in a semi-transparent state. The bar automatically hides again after a short delay, or if the user interacts with the middle of the screen.

To implement this just add the following method to your activity:

Источник

Оцените статью