国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Android實現布局全屏

瀏覽:20日期:2022-09-18 18:23:53

本文實例為大家分享了Android實現布局全屏的具體代碼,供大家參考,具體內容如下

前言

類似Launcher,希望占用的布局鋪滿全屏,以調整狀態欄及虛擬按鍵部分的顏色樣式。

廢話不多說,上案例:

一、效果預覽

Android實現布局全屏

二、案例實現

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'<!-- 測試設置的顏色 --> android:fitsSystemWindows='true' tools:context='.MainActivity'> <Buttonandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:text='測試'> </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); } //關鍵方法 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'> <applicationandroid: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”,如果不增加這個屬性,子view的布局會從最頂上開始,有興趣的可以修改了試試。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 久久精品国产一区二区 | 3至13呦女毛片 | 亚洲欧美一区二区久久香蕉 | 中文字幕亚洲不卡在线亚瑟 | 一区毛片| 国产成a人片在线观看视频 国产成版人视频网站免费下 | 91精品国产91久久久久久青草 | 国产91免费在线 | 国产一区二区三区久久精品小说 | 黄色美女视频 | 久久亚洲人成国产精品 | 美女视频黄的免费看网站 | 欧美69xx | 欧美成人自拍 | 中文字幕播放 | 一级欧美 | 99精品这里只有精品高清视频 | 另类视频一区 | 色九| 亚洲综合无码一区二区 | 中文字幕无线码中文字幕网站 | 久久精品国产欧美日韩亚洲 | 欧美视频一区二区三区四区 | 特级毛片全部免费播放器 | 国产福利最新手机在线观看 | 一区二区播放 | 日本一级特黄特色大片免费视频 | 亚洲欧美中文字幕在线网站 | 欧美特级一级毛片 | 国内真实愉拍系列情侣 | 91精品观看91久久久久久 | 九九热视频在线免费观看 | 在线视频观看一区 | 亚洲视频 欧美视频 | 成人高清在线观看播放 | 中文字幕成人免费高清在线 | 久久视频免费观看 | 日本vs欧美一区二区三区 | 日本天堂免费 | 日本美女作爱 | 曰本女同互慰高清在线观看 |