Android隐藏标题栏的四种方法

1. 使用actionBar.hide()方法
public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide(); //隐藏标题栏
}
}

2. 在布局加载之前隐藏
public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}

3. 在AndroidManifest.xml中配置
<!-- 这是全局隐藏 -->
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
</application> 
<!-- 只在MainActivity中去除 -->
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
</activity> 
4. 高度定制——在styles.xml中修改
方法a 打开res/values/styles.xml,将“AppTheme”的值更改为以下代码:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
...
</style>

</resources> 
这样所有界面的标题栏都消失了。其中Theme.AppCompat.Light.NoActionBar表示淡色主题,你也可以换用深色主题的:Theme.AppCompat.NoActionBar(注意暗色主题可不是“Dark”,而是把“Light”一词去掉)

方法b 或者在styles.xml中新自定义一个主题

<resources>

<style name="NoTheme" parent="AppTheme">
<item name="android:windowNoTitle">true</item>
</style>

</resources> 
该方法可以很方便地对主题进行定制


————————————————
版权声明:本文为CSDN博主「Likianta Me」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Likianta/article/details/78607911

原文地址:https://www.cnblogs.com/javalinux/p/14583141.html