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

来源:互联网 发布:悦诗风吟寒兰面霜知乎 编辑:程序博客网 时间:2024/06/10 01:15

1.依赖android-support-v7-appcompat

 1.1 getSupportActionBar().hide();必须放在setContentView之前,这种只能解决单个activity的问题。public class MainActivity extends AppCompatActivity{@Overrideprotected 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,这种的话网上很多,基本都对

@Overrideprotected 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">

 


0 0
原创粉丝点击