Android:制作全屏应用 [英] Android: making a fullscreen application
问题描述
对于最新版本的Android Studio创建的新的空白活动,我可以做的最简单的更改是什么,以使应用程序全屏显示?
What is the simplest change that I can make to a new Blank Activity, as created by the latest version of Android Studio, to get the app to appear fullscreen?
我要创建一个全屏Android应用程序。我正在使用Android Studio。
这篇文章建议我添加一行,例如...
I want to create a fullscreen Android application. I'm working with Android Studio. This post suggests that I add a line such as ...
android:theme = @ android:style / Theme.Holo.Light.NoActionBar.Fullscreen
...到AndroidManifest.xml文件,如下所示:
... to the AndroidManifest.xml file, as shown below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lexogram.james.blackslate" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.lexogram.james.blackslate.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
执行此操作时,应用程序会编译,但在启动时会崩溃。如果我删除该行,则该应用程序可以正常运行,但具有操作栏和标题栏(如其他用户所述)。
When I do this, the app compiles but it crashes on launch. If I remove the line, the app runs fine, but with the action bar and a title bar, as also noted by other users.
这是我第一次尝试创建一个Android应用程序,因此我的应用程序与原始的Hello World示例几乎没有变化。
This is my first attempt at creating an Android app, so my app is hardly altered from the original Hello World example.
编辑:
我创建了一个新项目,并做了一个更改对它。以下是错误日志的摘录:
I created a new project, and made just this one change to it. Here is an extract from the error log:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lexogram.james.test/com.lexogram.james.test.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)...
注意:我正在运行Android 2.2(Froyo)的旧三星SGH-T499Y上进行测试
NOTE: I am testing on a old Samsung SGH-T499Y, running Android 2.2 (Froyo)
推荐答案
您正在遇到此问题因为您尝试将 android:theme = @ android:style / Theme.Holo.Light.NoActionBar.Fullscreen>
应用于的活动正在扩展ActionBarActivity
You are getting this problem because the activity you are trying to apply the android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
to is extending ActionBarActivity which requires the AppCompat theme to be applied.
从 Activity
而不是从 ActionBarActivity扩展您的活动
您可能需要相应地更改Java类。
You might have to change your Java class accordingly little bit.
如果您也想删除状态栏,然后在 onCreateView
方法
If you want to remove status bar too then use this before setContentView(layout)
in onCreateView
method
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
这篇关于Android:制作全屏应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!