Android實(shí)現(xiàn)布局全屏
本文實(shí)例為大家分享了Android實(shí)現(xiàn)布局全屏的具體代碼,供大家參考,具體內(nèi)容如下
前言
類似Launcher,希望占用的布局鋪滿全屏,以調(diào)整狀態(tài)欄及虛擬按鍵部分的顏色樣式。
廢話不多說(shuō),上案例:
一、效果預(yù)覽
二、案例實(shí)現(xiàn)
1.新建Android工程
2.styles樣式增加
values 目錄的styles.xml添加如下樣式:
<style name="FullTheme" parent="@style/BaseFullTheme"> </style> <style name="BaseFullTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:colorBackgroundCacheHint">@null</item> <item name="android:windowShowWallpaper">true</item> <item name="android:windowNoTitle">true</item> </style>
alues-v19 目錄的styles.xml添加如下樣式:
<style name="FullTheme" parent="@style/BaseFullTheme"> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> </style>
values-v21目錄的styles.xml添加如下樣式:
<style name="FullTheme" parent="@style/BaseFullTheme"> <item name="android:windowTranslucentStatus">false</item> <item name="android:windowTranslucentNavigation">false</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">#00000000</item> <item name="android:navigationBarColor">#00000000</item> </style>
values-v29目錄的styles.xml添加如下樣式:
<style name="FullTheme" parent="@style/BaseFullTheme"> <item name="android:colorBackgroundCacheHint">@null</item> <item name="android:colorEdgeEffect">#FF757575</item> <item name="android:windowActionBar">false</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowShowWallpaper">true</item> <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> <item name="android:enforceStatusBarContrast">false</item> <item name="android:enforceNavigationBarContrast">false</item> <item name="android:windowTranslucentStatus">false</item> <item name="android:windowTranslucentNavigation">false</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">#00000000</item> <item name="android:navigationBarColor">#00000000</item> </style>
3.布局
layout目錄建立activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@android:color/holo_blue_bright"<!-- 測(cè)試設(shè)置的顏色 --> android:fitsSystemWindows="true" tools:context=".MainActivity"> <Button android:id="@+id/test" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="測(cè)試" > </Button> </LinearLayout>
4.使用
新建MainActivity.java
package com.demo; import android.app.Activity; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.view.View; import android.view.Window; import android.view.WindowManager; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); hideStatusBarNavigationBar(); setContentView(R.layout.activity_main); } //關(guān)鍵方法 private void hideStatusBarNavigationBar() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT); return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getWindow().addFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } } }
AndroidManifest.xml聲明
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.demo"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/FullTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
finish
三、填坑:fitsSystemWindows之坑
在activity_main.xml中的根布局那增加了android:fitsSystemWindows=“true”,如果不增加這個(gè)屬性,子view的布局會(huì)從最頂上開(kāi)始,有興趣的可以修改了試試。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android 設(shè)置應(yīng)用全屏的兩種解決方法
- Android編程實(shí)現(xiàn)WebView自適應(yīng)全屏方法小結(jié)
- android activity設(shè)置無(wú)標(biāo)題實(shí)現(xiàn)全屏
- Android 全屏無(wú)標(biāo)題欄的三種實(shí)現(xiàn)方法
- Android編程實(shí)現(xiàn)WebView全屏播放的方法(附源碼)
- android 設(shè)置全屏的兩種方法
- Android中3種全屏方法及3種去掉標(biāo)題欄的方法
- Android開(kāi)發(fā)之全屏與非全屏的切換設(shè)置方法小結(jié)
- Android下Activity全屏顯示實(shí)現(xiàn)方法
- Android4.2中全屏或者取消標(biāo)題欄的方法總結(jié)
相關(guān)文章
Android編程開(kāi)發(fā)之ScrollView嵌套GridView的方法
這篇文章主要介紹了Android編程開(kāi)發(fā)之ScrollView嵌套GridView的方法,結(jié)合實(shí)例分析了ScrollView嵌套GridView的相關(guān)注意事項(xiàng)與處理技巧,需要的朋友可以參考下2015-12-12Android實(shí)現(xiàn)沉浸式通知欄通知欄背景顏色跟隨app導(dǎo)航欄背景顏色而改變
這篇文章主要介紹了Android實(shí)現(xiàn)沉浸式通知欄通知欄背景顏色跟隨app導(dǎo)航欄背景顏色而改變的相關(guān)資料,需要的朋友可以參考下2016-02-02Android 中 requestWindowFeature()的應(yīng)用
本文主要介紹 Android requestWindowFeature()方法,這里對(duì) requestWindowFeature()方法進(jìn)行詳解,對(duì)應(yīng)用程序窗體顯示狀態(tài)的操作有進(jìn)一步了解,希望能幫助有需要的小伙伴2016-07-07android 仿微信demo——微信通訊錄界面功能實(shí)現(xiàn)(移動(dòng)端,服務(wù)端)
本系列文章主要介紹了微信小程序-閱讀小程序?qū)嵗╠emo),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,希望能給你們提供幫助2021-06-06Android自定義View實(shí)現(xiàn)投票進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)投票進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11MPAndroidChart 自定義圖表繪制使用實(shí)例
這篇文章主要為大家介紹了MPAndroidChart 自定義圖表繪制使用實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09