app/res/values/styles.xml文件中
标题栏隐藏
<item name="android:windowNoTitle">true</item>
状态栏隐藏
<item name="android:windowFullscreen">true</item>
一、如果MainActivity 继承自 Activity,用requestWindowFeature(Window.FEATURE_NO_TITLE)来隐藏:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 隐藏标题栏。注意防止setContentView()之前
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
二、如果MainActivity 继承自 AppCompatActivity,用getSupportActionBar().hide()来隐藏:
@Override
protected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 隐藏标题栏。注意防止setContentView()之前
if(getSupportActionBar() !=null){
getSupportActionBar().hide();
}
setContentView(R.layout.activity_main);