8

为了制作一个全屏应用程序,我对新的“空白活动”项目的清单进行了以下更改:

  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

应用程序在任何设备上运行时都会崩溃。StackOverflow 中的许多帖子都推荐了我所做的更改,但我无法弄清楚我做错了什么。

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <activity
        android:name="com.example.app.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
 </application>
</manifest>
4

5 回答 5

15

只需按照以下方式进行:

import android.support.v7.app.ActionBarActivity;

延长:

    public class SplashScreen extends ActionBarActivity {

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getSupportActionBar().hide();
            setContentView(R.layout.splash_screen);
    }
}

它在 API 级别 7 或更高级别上运行良好。

编辑:

使用AppCompatActivity因为ActionBarActivity在 API 23 中不推荐使用 @deprecated。

于 2014-04-26T07:12:29.483 回答
1

您可以像这样以编程方式执行此操作:(如果您使用它,则无需编辑清单文件)

 super.onCreate(savedInstanceState);
       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);  
于 2014-04-25T12:51:15.283 回答
0

为了全屏显示您的应用程序,请在 res-->values-->styles.xml 的 style.xml 文件中使用以下代码

android:theme="@android:style/Theme.Holo.Light.NoActionBar"

或者,在 Android 清单文件中提到的每个活动的编程代码中使用窗口管理器,如下所示...

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
于 2014-04-25T12:53:00.400 回答
0

将此包含在您的清单文件中。它会起作用的。

android:theme="@android:style/Theme.NoTitleBar"
于 2014-04-25T12:59:51.593 回答
-1
try
        {
            this.getSupportActionBar().hide();
        }
        catch (NullPointerException e){}

        setContentView(R.layout.activity_main);

这对我有用,试试这个!

于 2020-04-30T09:42:55.910 回答