android44狀態欄
A. Android設置狀態欄顏色和狀態欄文字、圖標顏色
Android開發中,經常需要實現下圖狀態欄的效果,類似於沉浸式狀態欄,但這里僅僅是討論設置狀態欄的顏色和狀態欄上面文字、圖標的顏色的方法。
Android 4.4(API 19)之後,就提供了修改狀態欄顏色的方法,但是在 Android 6.0(API 23)之後,才支持修改狀態欄上面的文字和圖標顏色,默認是白色的。所以會導致一個問題,在 4.4 到 6.0 之間的系統,狀態欄設置為淺色的話,狀態欄上面白色的文字和圖標會看不清,像下面這樣:
有一些第三方的系統提供了設置狀態欄和狀態欄文字、圖標顏色的方法,比如小米的MIUI和魅族的Flyme,所以考慮了下比較好的實現方式是:
當然,這裡面也會有坑,比如 MIUI 提供的修改狀態欄字體顏色方法會跟 Android 系統自帶的方法沖突,官方說明如下: 關於MIUI狀態欄字元顏色邏輯調整說明
經過網上的資料和自己的嘗試,MIUI 系統還是同時使用 MIUI 提供的方法和 Android 系統自帶的方法來修改狀態欄字體顏色比較保險。
基於上面的思考,封裝了設置 Android 4.4 以上系統狀態欄顏色和狀態欄字體、圖標顏色的方法:
要在 Application Theme 加上 <item name="android:fitsSystemWindows">true</item> ,不然頁面會頂到狀態欄上面,或者在 Activity 的布局裡面加上 android:fitsSystemWindows="true" 和 android:clipToPadding="false" 也可以。
最終實現的效果如下:
大家有更好的方案可以告訴我~
B. 安卓狀態欄高度是多少
問題一:App 安卓720*1280的狀態欄、導航欄、主菜單高度分別是50、96、96,那麼1080x1920的呢? 720*1280的密度與1080*1920的密度比 乘以高度就好了
問題二:如何修改手機狀態欄大物顫渣小和高度 反編譯framework-res.apk
2.打開res/values/dimens.xml文件
3.修改如下代碼:
25.0dip
25.0dip
4.第一個是狀態欄的高度,25.0dip是我們現在看到的高度
5.第二罩悄個是圖標的高度
6.回編譯,替換resources.arsc到原來的apk里
framework-res.apk文件位於/system/framework文件夾中
問題三:android 狀態欄高度是多少 可以通過以下方法獲取:
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier(
status_bar_height, dimen, android);
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
問題四:android 狀態欄高度是多少 可通過下面調用系統方法獲取精確的高度:
int resourceId = getResources().getIdentifier(status_bar_height, dimen, android);
獲取狀態欄高度
int statusBarHeight = getResources().getDimensionPixelSize(resourceId);
問題五:android狀態欄是多少dp 可以獲取到的。
Rect frame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
具體大小我好像記得是20dp.不太記得了
問題六:android狀態欄高度是多少 一般我覺得45dp就可以了
問題七:android中怎麼計算標題欄高度 getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);/取得整個視圖部分,注意,如果你要設置標題樣式,這個必須出現在洞裂標題樣式之後,否則會出錯
int top = rect.top;狀態欄的高度,所以rect.height,rect.width分別是系統的高度的寬度
View v = getWindow().findViewById(Window.ID_ANDROID_CONTENT);/獲得根視圖
int top2 = v.getTop();/狀態欄標題欄的總高度,所以標題欄的高度為top2-top
int width = v.getWidth();/視圖的寬度,這個寬度好像總是最大的那個
int height = v.getHeight();視圖的高度,不包括狀態欄和標題欄
如果只想取得屏幕大小,可以用
Display display = getWindowManager().getDefaultDisplay() ;
display.getWidth();
display.getHeight();代碼見@Overridepublic void onWindowFocusChanged(boolean hasFocus) {
TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
Rect frame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
狀態欄高度
int statusBarHeight = frame.top;
View v = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
int contentTop = v.getTop();
statusBarHeight是上面所求的狀態欄的高度
int titleBarHeight = contentTop - statusBarHeight;
textView = (TextView) findViewById(R.id.textView1);
textView.setText(標題欄的高度 + Integer.toString(titleBarHeight) +
+ 標題欄高度 + statusBarHeight +
+ 視圖的寬度 + v.getWidth()
+
+ 視圖的高度(不包含狀態欄和標題欄) + v.getHeight());
問題八:安卓480x800狀態欄和導航欄高度是多少 分別是12,48 dp @android/style裡面有寫的
問題九:如何修改 Android 狀態欄高度 反編譯framework-res.apk2.打開res/values/dimens.xml文件3.修改如下代碼:25.0dip25.0dip4.第一個是狀態欄的高度,25.0dip是我們現在看到的高度5.第二個是圖標的高度6.回編譯,替換resources.arsc到原來的apk里
framework-res.apk文件位於/system/framework文件夾中
問題十:android 狀態欄高度多少25dp 可以通過以下方法獲取:
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier(
status_bar_height, dimen, android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
C. Android 顯示、隱藏狀態欄和導航欄
Android 顯示、隱藏狀態欄和導航欄
控制狀態欄顯示,Activity的主題中配置全屏屬性
控制狀態欄顯示,在setContentView之前設置全屏的flag
控制狀態欄顯示,在任何位置通過添加和移除全屏的flag
控制狀態欄和導航欄顯示,setSystemUiVisibility
// 全屏展示
// 非全屏顯示,顯示狀態欄和導航欄
D. android怎麼改變狀態欄顏色
參考如下內容:
android4.4 以下修改狀態欄顏色的方法為:
1、首先會懂得反編譯,電腦上要安裝java環境和反編譯工具。沒有的網路搜索下載安裝。這里就不多說了。
2、要准備一個framework-res.apk放在一邊待用,把framework-res.apk復制到反編譯工具里、反編譯framework-res.apk後打開res\values\styles.xml。
3、直接搜索以下代碼
<style name="TextAppearance.StatusBar" parent="@style/TextAppearance">
你會看見<style name="TextAppearance.StatusBar" parent="@style/TextAppearance">
<item name="textSize">14.0sp</item>
<item name="textStyle">normal</item>
<item name="textColor">?textColorPrimary</item>
</style> 然後修改這一段代碼<item name="textColor">?textColorPrimary</item> 為 <item name="textColor">#ff000000</item>
000000為顏色代碼 想要什麼顏色就修改成自己喜歡的顏色就可以了 顏色對照表可以參考 http://www.59178.com/tools/sejie.asp
4、然後回編譯。回編譯完成後用電腦上的壓縮軟體打開回編譯好的framework-res.apk,拖出裡面的resources.arsc替換進事先准備好的framework-res.apk里就可以了。然後用復制到內存卡 用RE復制或者移動到system里 修改許可權 3 1 0,在移動到framework里覆蓋就可以了。關機重啟,狀態欄的通知內容顏色也變了。
E. Android 完全隱藏狀態欄方法
Android 完全隱藏狀態欄方法 https://blog.csdn.net/ljbphoebe/article/details/88179576
1. 隱藏ActionBar:
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.hide();
}
如果是繼承AppCompatActivity,就用getSupportActionBar()。
2. 隱藏狀態欄
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
通過這兩個步就可以全屏顯示啟動頁了。
然而,當開始動態申請許可權,彈出系統的許可權提示對話框後,狀態欄又重新露出來了。我日,不是隱藏了嗎?怎麼又出來了,什麼鬼?
通過查看源碼的解釋:
/**
* Request that the visibility of the status bar or other screen/window
* decorations be changed.
*
* <p>This method is used to put the over device UI into temporary modes
* where the user's attention is focused more on the application content,
* by dimming or hiding surrounding system affordances. This is typically
* used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY
* Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content
* to be placed behind the action bar (and with these flags other system
* affordances) so that smooth transitions between hiding and showing them
* can be done.
*
* <p>Two representative examples of the use of system UI visibility is
* implementing a content browsing application (like a magazine reader)
* and a video playing application.
*
* <p>The first code shows a typical implementation of a View in a content
* browsing application. In this implementation, the application goes
* into a content-oriented mode by hiding the status bar and action bar,
* and putting the navigation elements into lights out mode. The user can
* then interact with content while in this mode. Such an application should
* provide an easy way for the user to toggle out of the mode (such as to
* check information in the status bar or access notifications). In the
* implementation here, this is done simply by tapping on the content.
*
* {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java
* content}
*
* <p>This second code sample shows a typical implementation of a View
* in a video playing application. In this situation, while the video is
* playing the application would like to go into a complete full-screen mode,
* to use as much of the display as possible for the video. When in this state
* the user can not interact with the application; the system intercepts
* touching on the screen to pop the UI out of full screen mode. See
* {@link #fitSystemWindows(Rect)} for a sample layout that goes with this code.
*
* {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java
* content}
*
* @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE},
* {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN},
* {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION},
* {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}, {@link #SYSTEM_UI_FLAG_IMMERSIVE},
* and {@link #SYSTEM_UI_FLAG_IMMERSIVE_STICKY}.
*/
從釋義上可以知道,setSystemUiVisibility()是用於使系統UI進入一種臨時的模式,目的是使用戶的注意力關注於應用程序的內容上。所以單獨一個Activity這樣設置是可以全屏顯示的,這個只對當前的Activity有效。可是當申請系統許可權使,彈出的對話框是系統的Activity,通過adb shell mpsys activity 來看,當前最頂端的Activity已經是GrantPermissionsActivity。
Run #2: ActivityRecord{2b99111 u0 com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity t141}
而這個GrantPermissionsActivity,我們並無法去設置它的setSystemUiVisibility()。所以這種方法不奏效。
通過和同事討論,後來找到一種方法,可以實現我們的需求。
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
這種方法是OK的。
它的源碼釋義是:
/**
* Set the flags of the window, as per the
* {@link WindowManager.LayoutParams WindowManager.LayoutParams}
* flags.
*
* <p>Note that some flags must be set before the window decoration is
* created (by the first call to
* {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
* {@link #getDecorView()}:
* {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
* {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}. These
* will be set for you based on the {@link android.R.attr#windowIsFloating}
* attribute.
*
* @param flags The new window flags (see WindowManager.LayoutParams).
* @param mask Which of the window flag bits to modify.
* @see #addFlags
* @see #clearFlags
*/
public void setFlags(int flags, int mask) {}
仔細分析發現,這個是設置整個當前Window的,而setSystemUiVisibility()聚焦於顯示Activity內容的,還是有差別的。
/**
* Window flag: hide all screen decorations (such as the status bar) while
* this window is displayed. This allows the window to use the entire
* display space for itself -- the status bar will be hidden when
* an app window with this flag set is on the top layer. A fullscreen window
* will ignore a value of {@link #SOFT_INPUT_ADJUST_RESIZE} for the window's
* {@link #softInputMode} field; the window will stay fullscreen
* and will not resize.
*
* <p>This flag can be controlled in your theme through the
* {@link android.R.attr#windowFullscreen} attribute; this attribute
* is automatically set for you in the standard fullscreen themes
* such as {@link android.R.style#Theme_NoTitleBar_Fullscreen},
* {@link android.R.style#Theme_Black_NoTitleBar_Fullscreen},
* {@link android.R.style#Theme_Light_NoTitleBar_Fullscreen},
* {@link android.R.style#Theme_Holo_NoActionBar_Fullscreen},
* {@link android.R.style#Theme_Holo_Light_NoActionBar_Fullscreen},
* {@link android.R.style#Theme_DeviceDefault_NoActionBar_Fullscreen}, and
* {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_Fullscreen}.</p>
*/
public static final int FLAG_FULLSCREEN = 0x00000400;
從釋義上得知,設置這個flag可以隱藏所有的屏幕修飾,像status bar,用於Window使用整個顯示屏。這個完全是我們的目的了。
F. 如何修改 Android 狀態欄高度
反編譯framework-res.apk
2.打開res/values/dimens.xml文件
3.修改如下代碼:
<dimen
name="status_bar_height">25.0dip</dimen>
<dimen
name="status_bar_icon_size">25.0dip</dimen>
4.第一個是狀態欄的高度,25.0dip是我們現在看到的高度
5.第二個是圖標的高度
6.回編譯,替換resources.arsc到原來的apk里
framework-res.apk文件位於/system/framework文件夾中
G. android 狀態欄顯示不下怎麼辦
是的,說明這系統和你的手機不兼容
H. android 怎麼實現顯示狀態欄
droid想要應用運行時全屏有一種方法是在activity的onCreat方法中加入如下代碼:getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);並且需要在setContentView()之前,否則無效過。從這么多的苛刻條件可以看出這種方法無法滿足動態控制。
下面的方法可以滿足這個需要。調用View的 setSystemUiVisibility()
方法,其參數如下:
復制代碼代碼如下:
View.SYSTEM_UI_FLAG_FULLSCREEN, //全屏,狀態欄和導航欄不顯示
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION, //隱藏導航欄
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, //全屏,狀態欄會蓋在布局上
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION,
View.SYSTEM_UI_FLAG_LAYOUT_STABLE,
View.SYSTEM_UI_FLAG_LOW_PROFILE,
View.SYSTEM_UI_FLAG_VISIBLE, //顯示狀態欄和導航欄
I. Android 沉浸式/透明式狀態欄、導航欄
Android 從4.4開始引進透明狀態欄和導航欄的概念,並且在5.0進行了改進,將透明變成了半透明的效果。雖然此特性最早出現在ios,但不否認效果還是很贊的。
至於4.4以下的手機,就不要考慮此特性了,好在4.4以下的手機份額已經非常小了。
我們先來看一下透明狀態欄的實現,兩種常見效果圖如下:
虛擬導航欄並不是所有的手機都有,華為的手機多比較常見,就是上圖屏幕底部按鈕那塊區域。設置導航欄和狀態欄類似:
這是官方的解釋,大致意思就是我們在布局的最外層設置 android:fitsSystemWindows="true",會在屏幕最上方預留出狀態欄高度的padding。
由於fitsSystemWindows屬性本質上是給當前控制項設置了一個padding,所以我們設置到根布局的話,會導致狀態欄是透明的,並且和窗口背景一樣。
但是多數情況,我們並不在根布局設置這個屬性,我們想要的無外乎是讓內容沉浸在狀態欄之中。所以我們經常設置在最上端的圖片背景、Banner之類的,如果是Toolbar的,我們可以使用一層LinearLayout包裹,並把這個屬性設置給LinearLayout,這樣就可以避免Toolbar的內容下沉了。如:
上述方法可以解決普通頁面的透明式狀態欄需求,如有復雜需求可以參考下面這些:
Android 系統狀態欄沉浸式/透明化完整解決方案
Android 沉浸式狀態欄的實現
Android沉浸式狀態欄(透明狀態欄)最佳實現
還有開源庫推薦: ImmersionBar
J. Android去除狀態欄的方法匯總
一、隱藏標題欄
//隱藏標題欄
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
二、隱藏狀態欄
//隱藏狀態欄
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
三、去掉所有Activity界面的標題欄
修改AndroidManifest.xml
在application 標簽中添加android:theme="@android:style/Theme.NoTitleBar"
四、去掉所有Activity界面的TitleBar 和StatusBar
修改AndroidManifest.xml
在application 標簽中添加
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"