您的位置:首页 > 移动开发 > Android开发

android隐藏标题栏个人心得,欢迎指正

2016-12-01 11:37 363 查看

1.依赖android-support-v7-appcompat

1.1 getSupportActionBar().hide();必须放在setContentView之前,这种只能解决单个activity的问题。

public class MainActivity extends AppCompatActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去除标题栏
getSupportActionBar().hide();
setContentView(R.layout.activity_main);

1.2     把parent改变一下,另外再加一个item“windowNoTitle”,application节点下的them不用改变,
也可以自定义style,但做法跟这个一样,只不过名字换了。但是这种在6.0系统上,我感觉黑色的字体变浅了
,不知道咋回事,求大神告知
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->

<item name="windowNoTitle">true</item>
</style>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">>




2.不依赖android-support-v7-appcompat

2.1,这种的话网上很多,基本都对

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去除标题栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);2.2,在style下多加个item,其余不变
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->

<item name="windowNoTitle">true</item>
</style>



2.3,在application节点下的theme主题换下

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息