使用 java 代码隐藏 ActionBarActivity 中的标题栏

Hide tittle bar in ActionBarActivity using java code

如何在 Android ActionBarActivity 中隐藏标题栏 我什么都试过了,还是没成功。

获取异常:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dan.msdashboard/com.dan.msdashboard.FirstActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

但我正在使用此代码

protected void onCreate(Bundle savedInstanceState) {
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

            // Hide the Title bar of this activity screen


        this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_simple);

请帮我解决。

提前致谢....

在 onCreate 之前做特征

protected void onCreate(Bundle savedInstanceState) {
        // requestWindowFeature(Window.FEATURE_NO_TITLE);

  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);


        super.onCreate(savedInstanceState);



            // Hide the Title bar of this activity screen


        this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_simple);

在调用 super.onCreate() 之前设置 window 标志:

protected void onCreate(Bundle savedInstanceState) {
        getWindow()...
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple);
}

一次尝试如下

     // requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Hide the Title bar of this activity screen
    this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_simple);

希望对您有所帮助。

试试这个代码

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;


public class MainActivity extends ActionBarActivity {

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

在你的AndroidManifest.xml

如果您正在使用 AppCompat

activity标签中加一个attribute隐藏ActionBar

android:theme="@style/Theme.AppCompat.NoActionBar"