Activity與AppCompatActivity去掉標題欄

Activity與AppCompatActivity去掉標題欄

Activity去標題欄

1.代碼中實現

requestWindowFeature(Window.FEATURE_NO_TITLE);
//這句代碼必須寫在setContentView()前面

2.在清單文件(manifest.xml)裏面實現

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

<!--或者只對某個activity設置-->
<activity android:name="xxxx.xxxxx.xxxx.activity"
            android:theme="@android:style/Theme.NoTitleBar"/>

3.在style.xml文件裏定義

<?xml version="1.0" encoding="UTF-8" ?>  
<resources>  
    <style name="notitle">  
        <item name="android:windowNoTitle">true</item>  
    </style>   
</resources>

然後在manifest.xml中引用就可以了

<application android:icon="@drawable/icon"   
        android:label="@string/app_name"   
        android:theme="@style/notitle"> 

<!--或者只對某個activity設置-->
<activity android:name="xxxx.xxxxx.xxxx.activity"
            android:theme="@style/notitle"/>

AppCompatActivity去標題欄

1.代碼中實現,這裏有兩種方式

//方式一:這句代碼必須寫在setContentView()方法的後面
getSupportActionBar().hide();

//方式二:這句代碼必須寫在setContentView()方法的前面
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

2.在清單文件(manifest.xml)裏面實現

<application
   android:theme="@style/Theme.AppCompat.NoActionBar">

<!--或者只對某個activity設置-->
<activity android:name="xxxx.xxxxx.xxxx.activity"
            android:theme="@style/Theme.AppCompat.NoActionBar"/>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章