android全屏去掉title欄的多種實現(xiàn)方法
更新時間:2013年02月18日 09:48:17 作者:
android全屏去掉title欄包括以下幾個部分:實現(xiàn)應(yīng)用中的所有activity都全屏/實現(xiàn)單個activity全屏/實現(xiàn)單個activity去掉title欄/自定義標(biāo)題內(nèi)容/自定義標(biāo)題布局等等感興趣的可參考下啊
1.實現(xiàn)應(yīng)用中的所有activity都全屏
在manifest中直接加入
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
2.實現(xiàn)單個activity全屏
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.TYPE_STATUS_BAR, WindowManager.LayoutParams.TYPE_STATUS_BAR);
3.實現(xiàn)單個activity去掉title欄
requestWindowFeature(Window.FEATURE_NO_TITLE);
1、改變標(biāo)題內(nèi)容:public void setTitle (CharSequence title)
2、隱藏標(biāo)題:requestWindowFeature(Window.FEATURE_NO_TITLE);
3、隱藏標(biāo)題和最上面的電池電量及信號欄(全屏):
public void setFullscreen() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
4、自定義標(biāo)題內(nèi)容
<activity android:name=".activity.MainActivity" android:screenOrientation="portrait" android:label="@string/titlebar_text"
</actibity> 2)
MainActivity文件中:
requestWindowFeature(Window.FEATURE_NO_TITLE);
//設(shè)置窗口無標(biāo)題欄
setContentView(R.layout.main);
//動態(tài)設(shè)置標(biāo)題的值,getTitle()的值是該activity的聲明中android:label的值
((TextView) findViewById(R.id.titlebar_text)).setText(getTitle());
其中,getTitle()取得的值就是上述 android:label="@string/titlebar_text" 的值
5、自定義標(biāo)題布局
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//預(yù)先設(shè)置允許改變的窗口狀態(tài),需在 setContentView 之前調(diào)用,否則設(shè)置標(biāo)題時拋運行時錯誤。
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
//標(biāo)題區(qū)域可設(shè)置為 layout ,如此可以有豐富的展現(xiàn)方式
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title_1);
}
res\layout\custom_title_1.xml 包含一個TextView 用于顯示標(biāo)題。Android可以把標(biāo)題做為一個layout來展示,具有很好的擴(kuò)展性。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="@+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/custom_title_left" />
</RelativeLayout>
在manifest中直接加入
復(fù)制代碼 代碼如下:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
2.實現(xiàn)單個activity全屏
復(fù)制代碼 代碼如下:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.TYPE_STATUS_BAR, WindowManager.LayoutParams.TYPE_STATUS_BAR);
3.實現(xiàn)單個activity去掉title欄
復(fù)制代碼 代碼如下:
requestWindowFeature(Window.FEATURE_NO_TITLE);
1、改變標(biāo)題內(nèi)容:public void setTitle (CharSequence title)
2、隱藏標(biāo)題:requestWindowFeature(Window.FEATURE_NO_TITLE);
3、隱藏標(biāo)題和最上面的電池電量及信號欄(全屏):
復(fù)制代碼 代碼如下:
public void setFullscreen() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
4、自定義標(biāo)題內(nèi)容
復(fù)制代碼 代碼如下:
<activity android:name=".activity.MainActivity" android:screenOrientation="portrait" android:label="@string/titlebar_text"
</actibity> 2)
MainActivity文件中:
復(fù)制代碼 代碼如下:
requestWindowFeature(Window.FEATURE_NO_TITLE);
//設(shè)置窗口無標(biāo)題欄
setContentView(R.layout.main);
//動態(tài)設(shè)置標(biāo)題的值,getTitle()的值是該activity的聲明中android:label的值
((TextView) findViewById(R.id.titlebar_text)).setText(getTitle());
其中,getTitle()取得的值就是上述 android:label="@string/titlebar_text" 的值
5、自定義標(biāo)題布局
復(fù)制代碼 代碼如下:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//預(yù)先設(shè)置允許改變的窗口狀態(tài),需在 setContentView 之前調(diào)用,否則設(shè)置標(biāo)題時拋運行時錯誤。
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
//標(biāo)題區(qū)域可設(shè)置為 layout ,如此可以有豐富的展現(xiàn)方式
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title_1);
}
res\layout\custom_title_1.xml 包含一個TextView 用于顯示標(biāo)題。Android可以把標(biāo)題做為一個layout來展示,具有很好的擴(kuò)展性。
復(fù)制代碼 代碼如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="@+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/custom_title_left" />
</RelativeLayout>
您可能感興趣的文章:
- Android調(diào)用默認(rèn)瀏覽器打開指定Url的方法實例
- android webview 簡單瀏覽器實現(xiàn)代碼
- android 瀏覽器之多窗口方案詳解
- Android調(diào)用系統(tǒng)默認(rèn)瀏覽器訪問的方法
- Android自定義 WebView瀏覽器
- Android 設(shè)置應(yīng)用全屏的兩種解決方法
- android activity設(shè)置無標(biāo)題實現(xiàn)全屏
- android 設(shè)置全屏的兩種方法
- Android下Activity全屏顯示實現(xiàn)方法
- Android 全屏無標(biāo)題欄的三種實現(xiàn)方法
- android屏幕全屏的實現(xiàn)代碼
- Android開發(fā)實現(xiàn)瀏覽器全屏顯示功能
相關(guān)文章
Android編程實現(xiàn)監(jiān)控各個程序流量的方法
這篇文章主要介紹了Android編程實現(xiàn)監(jiān)控各個程序流量的方法,涉及Android針對應(yīng)用包的遍歷,權(quán)限控制及相關(guān)屬性操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-12-12Android帶刷新時間顯示的PullToRefresh上下拉刷新
這篇文章主要為大家詳細(xì)介紹了Android帶刷新時間顯示的PullToRefresh上下拉刷新,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-12-12Android獲取設(shè)備隱私 忽略6.0權(quán)限管理
這篇文章主要介紹了Android獲取設(shè)備隱私,忽略6.0權(quán)限管理,感興趣的小伙伴們可以參考一下2016-01-01Android獲取雙卡雙待手機(jī)的SIM卡信息示例代碼
這篇文章主要給大家介紹了關(guān)于Android獲取雙卡雙待手機(jī)的SIM卡信息的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11Android實現(xiàn)EditText控件禁止輸入內(nèi)容的方法(附測試demo)
這篇文章主要介紹了Android實現(xiàn)EditText控件禁止輸入內(nèi)容的方法,涉及Android針對EditText控件屬性設(shè)置的相關(guān)技巧,需要的朋友可以參考下2015-12-12