gpt4 book ai didi

android - 显示状态栏并改变颜色

转载 作者:行者123 更新时间:2023-11-30 00:28:15 24 4
gpt4 key购买 nike

我正在尝试让我的 Activity 显示我的状态栏。

without statusbar

我的 Activity 风格是这样的:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="Theme.AppCompat">
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/ActionBarTheme</item>
<item name="android:actionMenuTextColor">@color/ifix_gray_dark</item>
<item name="android:typeface">serif</item>
<item name="android:windowContentOverlay">@null</item>
<item name="colorControlActivated">@color/white</item>

<item name="actionBarStyle">@style/ActionBarTheme</item>
<item name="actionMenuTextColor">@color/ifix_gray_dark</item>
</style>

<style name="ActivityBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<item name="actionBarSize">35dp</item>
</style>

<style name="ActionBarTheme" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@drawable/actionbar_background</item>
<item name="android:backgroundStacked">@drawable/actionbar_background</item>
<item name="android:backgroundSplit">@drawable/actionbar_background</item>

<item name="background">@drawable/actionbar_background</item>
<item name="backgroundStacked">@drawable/actionbar_background</item>
<item name="backgroundSplit">@drawable/actionbar_background</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="buttonTint">@color/rosa_iguana</item>
</style>
</resources>

对于 Style v21,我有:

 <style name="ActivityBar" parent="Theme.AppTheme.NoActionBar">
<item name="colorPrimaryDark">@color/black</item>
<item name="android:statusBarColor">@color/black</item>
</style>

我找到这段代码来显示我的状态栏,但我把它涂成了白色

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
hideSystemUI(hasFocus);
}

@TargetApi(Build.VERSION_CODES.KITKAT)
private void hideSystemUI(boolean hasFocus) {
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
}

example status bar white here

我的 list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.projextx">
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<!-- for card.io card scanning -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Added for MobileAppTracking -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application
android:name=".Application"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@drawable/launcher_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".activities.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.ActivitySelectCountry"
android:screenOrientation="portrait" />
<activity
android:name=".activities.HomeActivity"
android:screenOrientation="portrait"
android:theme="@style/ActivityBar"
android:windowSoftInputMode="adjustPan"/>
<activity
android:name=".activities.ActivitySegment"
android:screenOrientation="portrait"/>
<activity
android:name=".activities.ActivityProductDetail"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.ActivityPagerPagoOption"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan" />
</application>
</manifest>

我真的很想在样式中使用一些解决方案,因为我必须将它应用到另外 2 个 Activity 中。

感谢您的帮助。

最佳答案

最后我不知道为什么状态栏不显示但是这段代码解决了我的问题:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
hideSystemUI(hasFocus);
}

@TargetApi(Build.VERSION_CODES.KITKAT)
private void hideSystemUI(boolean hasFocus) {
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getColor(R.color.black));
}
}
}

感谢您的帮助。

关于android - 显示状态栏并改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44977845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com