如何从Android ActionBarActivity隐藏标题栏 我已经尝试了一切,但没有取得成功。
得到那个例外:
java.lang.RuntimeException:无法启动活动 ComponentInfo {com.dan.msdashboard / com.dan.msdashboard.FirstActivity}: android.util.AndroidRuntimeException:必须调用requestFeature() 在添加内容之前
但我正在使用此代码
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);
请帮我解决。
提前致谢....
答案 0 :(得分:0)
在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);
答案 1 :(得分:0)
在调用super.onCreate()
之前设置窗口标志:
protected void onCreate(Bundle savedInstanceState) {
getWindow()...
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple);
}
答案 2 :(得分:0)
尝试如下
// 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);
希望这会对你有所帮助。
答案 3 :(得分:0)
试试这段代码
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();
}
}
答案 4 :(得分:0)
在AndroidManifest.xml
如果您使用AppCompat
在attribute
标记中添加一个activity
以隐藏ActionBar
android:theme="@style/Theme.AppCompat.NoActionBar"