我想以编程方式更改前 Lollipop 设备上的状态栏颜色。我很清楚 Material 设计 colouPrimaryDark 不会在 Lollipop 之前工作,因为状态栏颜色是操作系统本身的关注点, Lollipop 之前的设备不会提供这样的功能。所以我想通过 java 文件以编程方式进行。这可能吗?
目前我正在使用这个 Material 设计代码。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryColor</item>
<item name="colorAccent">@color/primaryColor</item>
</style>
因为这不适用于 21 以下的 API。所以我想通过 java 来完成。
最佳答案
实际上,我们可以在 + KitKat
上使用它。
检查此链接: http://developer.android.com/reference/android/R.attr.html#windowTranslucentStatus
- Has been added in
API level 19
which means, there is a way to do that.check my blog about using it withSystemTintBar
: https://linx64.ir/blog/2016/02/05/translucent-statusbar-on-kitkat/- And this is the another method(without using
CoordinatorLayout
): Translucent StatusBar on kitkat with FrameLayout above the Toolbar and using CoordinatorLayout
只需将其添加到布局的顶部:
<FrameLayout
android:id="@+id/statusbar"
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="@color/colorPrimaryDark" />
然后使用这个:
if(Build.VERSION.SDK_INT == 19) {
FrameLayout statusbar = (FrameLayout) findViewById(R.id.statusbar);
statusbar.setVisibility(View.GONE);
}
它应该在 Kitkat
上工作,就像我说的,这也只适用于 + Kitkat
。
关于Android - 以编程方式更改 Lollipop 前设备上的状态栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35307531/