最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決Android 沉浸式狀態(tài)欄和華為虛擬按鍵沖突問題

 更新時(shí)間:2017年07月18日 09:51:16   作者:LiuWaiterC  
對于現(xiàn)在的 App 來說,布局頁面基本都會(huì)用到沉浸式狀態(tài)欄,單純的沉浸式狀態(tài)欄很容易解決,但是在華為手機(jī)上存在一個(gè)底部虛擬按鍵的問題,會(huì)導(dǎo)致頁面底部和頂部出現(xiàn)很大的問題,下面通過本文給大家分享Android 沉浸式狀態(tài)欄和華為虛擬按鍵沖突問題,一起看看吧

對于現(xiàn)在的 App 來說,布局頁面基本都會(huì)用到沉浸式狀態(tài)欄,單純的沉浸式狀態(tài)欄很容易解決,但是在華為手機(jī)上存在一個(gè)底部虛擬按鍵的問題,會(huì)導(dǎo)致頁面底部和頂部出現(xiàn)很大的問題,比如頁面底部導(dǎo)航欄被按鍵覆蓋,導(dǎo)致底部無法操作,頂部狀態(tài)欄布局被撐的很高,丑的不忍直視,這里就將兩者的沖突問題一并解決!先看下實(shí)現(xiàn)的效果圖:

這里寫圖片描述

這是我自己的手機(jī),OnePlus 3T 7.1.1版本(免費(fèi)廣告,沒給我錢的?。?,不是華為的手機(jī),但是有個(gè)虛擬按鍵可以設(shè)置,可以看到底部導(dǎo)航欄沒有問題,頂部狀態(tài)欄也成功實(shí)現(xiàn),效果圖看完,下面直接飆車了:

主頁面布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.example.statusbarvirtualkey.statusbarvirtualkey.MainActivity">
 <RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent">
 <include
 android:id="@+id/home_title"
 layout="@layout/layout_home_title" />
 <FrameLayout
 android:id="@+id/home_container"
 android:layout_width="match_parent"
 android:layout_height="0dp"
 android:layout_alignParentTop="true"
 android:layout_marginTop="70dp"
 android:layout_above="@+id/line_bottom"
 android:layout_weight="1"
 >
 </FrameLayout>
 <View
 android:id="@+id/line_bottom"
 android:layout_width="match_parent"
 android:layout_height="0.5dp"
 android:alpha="0.6"
 android:layout_above="@+id/bottom_navigation_view"
 android:background="@android:color/darker_gray"
 />
 <android.support.design.widget.BottomNavigationView
 android:id="@+id/bottom_navigation_view"
 android:layout_width="match_parent"
 android:layout_height="50dp"
 android:layout_alignParentBottom="true"
 app:itemBackground="@android:color/white"
 app:elevation="2dp"
 app:itemTextColor="@color/selector_item_color"
 app:itemIconTint="@color/selector_item_color"
 app:menu="@menu/navigation_menu"
 >
 </android.support.design.widget.BottomNavigationView>
 </RelativeLayout>
</RelativeLayout>

底部導(dǎo)航欄用到的是 BottomNavigationView,AndroidStudio 直接引入,由于這個(gè)不是本篇文章的重點(diǎn)部分,此處不作詳細(xì)介紹,想看具體實(shí)現(xiàn)可以看我的源代碼,頂部是一個(gè)自定義的 ToolBar,代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:id="@+id/myToolBar"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@drawable/layer_list_bottom_line"
 android:padding="@dimen/titleBarPadding"
 android:elevation="@dimen/primary_shadow_height"
 android:clipToPadding="true"
 android:fitsSystemWindows="true"
 app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
 <RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent">
 <TextView
 android:id="@+id/home_left"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerVertical="true"
 android:drawableLeft="@mipmap/ind_icon_fan"
 android:drawablePadding="5dp"
 android:padding="@dimen/dp_4" />
 <TextView
 android:id="@+id/home_right"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentEnd="true"
 android:layout_alignParentRight="true"
 android:layout_centerVertical="true"
 android:ellipsize="end"
 android:singleLine="true"
 android:maxEms="5"
 android:textColor="@android:color/black"
 android:textSize="7.0sp"
 android:typeface="monospace" />
 <TextView
 android:id="@+id/toolbar_title"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerInParent="true"
 android:singleLine="true"
 android:text="@string/app_name"
 android:textColor="@android:color/white"
 android:textSize="20sp" />
 </RelativeLayout>
</android.support.v7.widget.Toolbar>

需要注意的是Android:fitsSystemWindows這個(gè)屬性,主要是通過調(diào)整當(dāng)前設(shè)置這個(gè)屬性的view的padding去為我們的status_bar留下空間,如果不寫,布局會(huì)出很嚴(yán)重的問題,可以自己去試驗(yàn)不寫的后果…

介紹完基本布局,接下來是如何設(shè)置沉浸式狀態(tài)欄呢,在 AndroidManifest 布局中,設(shè)置主題:

<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/AppTheme">
 <activity android:name=".MainActivity">
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>
 </application>

這里需要注意的是,需要設(shè)置 3 個(gè)文件夾,分別對應(yīng)的 android 版本不一致,values,values-v19,values-v21,values目錄下設(shè)置:

<style name="AppTheme" parent="@style/BaseAppTheme">
 </style>
 <style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
 <item name="colorPrimary">@color/colorPrimary</item>
 <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
 <item name="colorAccent">@color/colorAccent</item>
 </style>

values-v19:

<style name="AppTheme" parent="@style/BaseAppTheme">
 <item name="android:windowTranslucentStatus">true</item>
 <item name="android:windowTranslucentNavigation">false</item>
 </style>

values-v21:

<style name="AppTheme" parent="BaseAppTheme">
 <item name="android:statusBarColor">@color/colorPrimary</item>
 <item name="android:windowDrawsSystemBarBackgrounds">true</item>
 </style>

注意了,接下來就是Activity里面的重點(diǎn)操作了,這里介紹只貼重點(diǎn)代碼,onCreate方法:

@Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 toolbar_title = (TextView) findViewById(R.id.toolbar_title);
 //下面的代碼可以寫在BaseActivity里面
 highApiEffects();
 mToolBar = (Toolbar) getWindow().findViewById(R.id.home_title);
 setSupportActionBar(mToolBar);
 }
@TargetApi(Build.VERSION_CODES.KITKAT)
 private void highApiEffects() {
 getWindow().getDecorView().setFitsSystemWindows(true);
 //透明狀態(tài)欄 @頂部
 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
 //透明導(dǎo)航欄 @底部 這一句不要加,目的是防止沉浸式狀態(tài)欄和部分底部自帶虛擬按鍵的手機(jī)(比如華為)發(fā)生沖突,注釋掉就好了
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
 }

高能預(yù)警?。?!這里一定要注意,getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);這句代碼千!萬!不!要!加!??!加了就會(huì)起沖突!到這里,沉浸式狀態(tài)欄和底部虛擬按鍵的沖突問題就得到解決了

最后,貼上我手機(jī)三個(gè)手機(jī)的沉浸式狀態(tài)欄截圖,4.4的手機(jī)沒有,(其實(shí)是懶得開模擬器…)抱歉不能貼上,這里分別是:

Android 4.2.2,無沉浸式狀態(tài):

這里寫圖片描述

Android 5.1:

這里寫圖片描述

Android 7.1.1,底部帶虛擬按鍵,也就是我們本篇文章的主題:

這里寫圖片描述

源碼下載

以上所述是小編給大家介紹的解決Android 沉浸式狀態(tài)欄和華為虛擬按鍵沖突問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android RxJava創(chuàng)建操作符Timer的方法

    Android RxJava創(chuàng)建操作符Timer的方法

    這篇文章主要為大家詳細(xì)介紹了Android RxJava創(chuàng)建操作符Timer的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android 安全加密:非對稱加密詳解

    Android 安全加密:非對稱加密詳解

    本文主要介紹Android 安全加密,非對稱加密的知識,這里整理了詳細(xì)的資料,及使用方法,有需要的小伙伴可以參考下
    2016-09-09
  • 如何在Android中高效管理圖片加載

    如何在Android中高效管理圖片加載

    在Android應(yīng)用中,優(yōu)化用戶體驗(yàn)尤其是圖像加載極為重要,本文介紹了如何通過構(gòu)建ImageCacheLoader類來實(shí)現(xiàn)圖片的緩存和網(wǎng)絡(luò)下載,包括從URL加載圖片、下載圖片、保存圖片到緩存和文件名提取等關(guān)鍵功能,本方法能有效提高應(yīng)用響應(yīng)速度,減少網(wǎng)絡(luò)流量
    2024-11-11
  • Android解析相同接口返回不同格式j(luò)son數(shù)據(jù)的方法

    Android解析相同接口返回不同格式j(luò)son數(shù)據(jù)的方法

    這篇文章主要介紹了Android解析相同接口返回不同格式j(luò)son數(shù)據(jù)的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08
  • Android中使用TextView實(shí)現(xiàn)文字跑馬燈效果

    Android中使用TextView實(shí)現(xiàn)文字跑馬燈效果

    本文主要介紹了Android中使用TextView實(shí)現(xiàn)文字走馬燈效果的方法解析。具有很好的參考價(jià)值。下面跟著小編一起來看下吧
    2017-04-04
  • Android仿微信雷達(dá)輻射搜索好友(邏輯清晰實(shí)現(xiàn)簡單)

    Android仿微信雷達(dá)輻射搜索好友(邏輯清晰實(shí)現(xiàn)簡單)

    仿微信雷達(dá)掃描,仿安卓微信、云播雷達(dá)掃描動(dòng)畫效果點(diǎn)擊中間的黑色圓圈開始掃描動(dòng)畫,再次點(diǎn)擊復(fù)位,需要這種效果的朋友可以自己下載看一下
    2016-02-02
  • Android開發(fā)之Notification手機(jī)狀態(tài)欄通知用法實(shí)例分析

    Android開發(fā)之Notification手機(jī)狀態(tài)欄通知用法實(shí)例分析

    這篇文章主要介紹了Android開發(fā)之Notification手機(jī)狀態(tài)欄通知用法,結(jié)合實(shí)例形式分析了Android Notification手機(jī)狀態(tài)欄通知的常見函數(shù)、功能及使用技巧,需要的朋友可以參考下
    2019-03-03
  • android實(shí)現(xiàn)RecyclerView列表單選功能

    android實(shí)現(xiàn)RecyclerView列表單選功能

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)RecyclerView列表單選功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • Android仿微信和QQ多圖合并框架(類似群頭像)的實(shí)現(xiàn)方法

    Android仿微信和QQ多圖合并框架(類似群頭像)的實(shí)現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于Android仿微信和QQ多圖合并框架的相關(guān)資料,其實(shí)就是我們平時(shí)所見的群聊頭像,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • Android MessageQueue消息隊(duì)列主要作用詳解

    Android MessageQueue消息隊(duì)列主要作用詳解

    Android 消息機(jī)制主要指的是 Handler 的運(yùn)行機(jī)制及其所依賴的 MessageQueue 和 Looper 的工作過程,Handler、MessageQueue、Looper組成一個(gè)相互聯(lián)系的整體。本文先從 MessageQueue 的源碼來說明其實(shí)現(xiàn)原理
    2023-02-02

最新評論

恩施市| 灵武市| 高密市| 宜阳县| 磐石市| 玉溪市| 三门县| 泽州县| 南安市| 湘乡市| 高台县| 岳西县| 体育| 故城县| 张家川| 兴安盟| 枣庄市| 屯留县| 钦州市| 介休市| 汕头市| 旌德县| 龙江县| 双江| 贺州市| 蒲城县| 剑川县| 隆化县| 喀喇沁旗| 内乡县| 吉安市| 旬阳县| 嘉善县| 余姚市| 集贤县| 长白| 开远市| 古田县| 民丰县| 达拉特旗| 石嘴山市|