AppCompat ActionBarActivity를 사용하여 상태 표시 줄 색상 변경
내 활동 중 하나에서을 사용하여 툴바 색상을 변경했습니다 Palette. 그러나 5.0을 사용 ActionBarActivity하는 장치 에서 status bar색상을 사용 하는 colorPrimaryDark활동 테마 의 색상은 매우 다르므로 두 가지 매우 다른 색상이 있으며 좋지 않습니다.
5.0 에서는 사용할 수 Window.setStatusBarColor()있지만 ActionBarActivity이것을 가지고 있지 않다는 것을 알고 있습니다 .
그래서 내 질문은 5.0에 있습니다. 상태 표시 줄 색상을 ActionBarActivity어떻게 바꿀 수 있습니까?
문제를 이해하지 못했습니다.
프로그래밍 방식으로 상태 표시 줄 색상을 변경하고 싶습니다 (장치에 Android 5.0이있는 경우)을 사용할 수 있습니다 Window.setStatusBarColor(). 액티비티가에서 파생되었는지 Activity또는 에서 파생되는지는 차이가 없어야합니다 ActionBarActivity.
그냥 해보십시오.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.BLUE);
}
방금 이것을 테스트 ActionBarActivity했으며 정상적으로 작동합니다.
참고 : 스타일 파일에 이미 설정된 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS플래그는 다음과 같이 프로그래밍 방식으로 values-v21설정할 필요가 없습니다 .
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
상태 표시 줄 색상을 변경하는 방법에는 여러 가지가 있습니다.
1) styles.xml 사용. android : statusBarColor 속성을 사용하여이 작업을 쉽고 정적 방법으로 수행 할 수 있습니다.
참고 :이 속성을 재질 테마와 함께 사용할 수도 있습니다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
2) Window 클래스의 setStatusBarColor (int) 메소드를 사용하여 동적으로 수행 할 수 있습니다. 그러나이 방법은 API 21 이상에서만 사용할 수 있습니다. 따라서 확인하십시오. 그렇지 않으면 앱이 더 낮은 기기에서 충돌 할 것입니다.
이 방법의 실제 예는 다음과 같습니다.
if (Build.VERSION.SDK_INT >= 21) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getResources().getColor(R.color.primaryDark));
}
여기서 primaryDark는 내 앱에서 사용하는 기본 색상의 700 색조입니다. colors.xml 파일에서이 색상을 정의 할 수 있습니다.
시도해보고 궁금한 점이 있으면 알려주십시오. 도움이 되길 바랍니다.
상태 표시 줄 색상이 AppCompat에서 아직 구현되지 않았다고 생각합니다. 사용 가능한 속성은 다음과 같습니다.
<!-- ============= -->
<!-- Color palette -->
<!-- ============= -->
<!-- The primary branding color for the app. By default, this is the color applied to the
action bar background. -->
<attr name="colorPrimary" format="color" />
<!-- Dark variant of the primary branding color. By default, this is the color applied to
the status bar (via statusBarColor) and navigation bar (via navigationBarColor). -->
<attr name="colorPrimaryDark" format="color" />
<!-- Bright complement to the primary branding color. By default, this is the color applied
to framework controls (via colorControlActivated). -->
<attr name="colorAccent" format="color" />
<!-- The color applied to framework controls in their normal state. -->
<attr name="colorControlNormal" format="color" />
<!-- The color applied to framework controls in their activated (ex. checked) state. -->
<attr name="colorControlActivated" format="color" />
<!-- The color applied to framework control highlights (ex. ripples, list selectors). -->
<attr name="colorControlHighlight" format="color" />
<!-- The color applied to framework buttons in their normal state. -->
<attr name="colorButtonNormal" format="color" />
<!-- The color applied to framework switch thumbs in their normal state. -->
<attr name="colorSwitchThumbNormal" format="color" />
( \ sdk \ extras \ android \ support \ v7 \ appcompat \ res \ values \ attrs.xml에서 )
이것을 사용해보십시오, 나는 이것을 사용했으며 v21에서 매우 잘 작동합니다.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimaryDark">@color/blue</item>
</style>
위의 답변에 감사드립니다 .xamarin.android MVVMCross 응용 프로그램에 대한 특정 R & D 후에 그 도움을 받았습니다.
메소드 OnCreate의 활동에 지정된 플래그
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
}
각 MvxActivity에 대해 테마는 다음과 같습니다.
[Activity(
LaunchMode = LaunchMode.SingleTop,
ScreenOrientation = ScreenOrientation.Portrait,
Theme = "@style/Theme.Splash",
Name = "MyView"
)]
SplashStyle.xml은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@color/app_red</item>
<item name="android:colorPrimaryDark">@color/app_red</item>
</style>
</resources>
그리고 V7 appcompact가 언급되었습니다.
지원
<item name="android:statusBarColor">@color/color_primary_dark</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
에서 Theme.AppCompat.Light.DarkActionBar나를 위해 일하지 않았다. 트릭은 styles.xml colorPrimaryDark과 함께 평소와 같이 제공합니다.android:colorPrimary
<item name="android:colorAccent">@color/color_primary</item>
<item name="android:colorPrimary">@color/color_primary</item>
<item name="android:colorPrimaryDark">@color/color_primary_dark</item>
그리고 설정에서
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
Window window = this.Window;
Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
}
code에서 상태 표시 줄 색상을 설정할 필요가 없었습니다.
'IT story' 카테고리의 다른 글
| 공백을 어떻게 분해하고 다듬을 수 있습니까? (0) | 2020.06.21 |
|---|---|
| 내 Github 리포지토리에서 파일을 가져 오려고 시도하는 경우 : "관련되지 않은 기록을 병합하지 않음" (0) | 2020.06.21 |
| 루비가 왜 메소드 오버로딩을 지원하지 않습니까? (0) | 2020.06.21 |
| bash가있는 변수의 대문자 첫 문자 (0) | 2020.06.21 |
| ImageView 주위의 원하지 않는 패딩 (0) | 2020.06.21 |