应用程序尝试隐藏标题栏时崩溃

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>

3
请提供您的整个AndroidManifest.xml文件和logcat日志。 - MrByte
2
崩溃 = 堆栈跟踪。发布它。 - shkschneider
可能是Android Theme.NoTitleBar doesnot work的重复问题。 - Alex van den Hoogen
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中已被弃用。


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);  

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);

你清理了你的项目吗? - CompEng

0
将此内容包含在您的清单文件中。它会起作用。
android:theme="@android:style/Theme.NoTitleBar"

看清楚我的答案。它不同于你正在使用的答案。 - ravi
你正在使用 android:theme="@android:style/Theme.NoTitleBar.Fullscreen",请改用 android:theme="@android:style/Theme.NoTitleBar"。 - ravi
@AnixPasBesoin你需要发布堆栈跟踪。崩溃可能是由于不同的原因。 - Raghunandan

-1
try
        {
            this.getSupportActionBar().hide();
        }
        catch (NullPointerException e){}

        setContentView(R.layout.activity_main);

这个方法对我有用,你也可以试试!


包 com.example.casser;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle; import android.view.View; import android.view.Window;public class MainActivity extends AppCompatActivity {@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { this.getSupportActionBar().hide(); } catch (NullPointerException e){} setContentView(R.layout.activity_main); }} - Laxman Srivastava

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接