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"