查阅文档发现有两个id
android.R.id.statusBarBackground
android.R.id.navigationBarBackground
使用findViewById,获取导航栏的可以得到,但要获取statusBar的总是为null,不知道为什么
查阅文档发现有两个id
android.R.id.statusBarBackground
android.R.id.navigationBarBackground
使用findViewById,获取导航栏的可以得到,但要获取statusBar的总是为null,不知道为什么
以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
在Android中,R.id.statusBarBackground 是用于获取状态栏背景的颜色。然而,R.id.navigationBarBackground 用于获取导航栏(顶部区域)的背景颜色。
为了获取状态栏背景,你需要通过以下方式:
android:background="?android:id/statusBarBackground"。getResources().getDrawable(R.drawable.your_image)来加载状态栏背景图片。示例代码如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_image"/>
</FrameLayout>
然后,在你的Activity或Fragment中使用 imageView1.getBackground() 获取状态栏背景图片,或者直接调用 imageView1.getDrawable() 来获取状态栏背景颜色。