안드로이드 9.0(파이)에서 야간 모드가 활성화되어 있는 경우에도 애플리케이션에서 야간 모드를 비활성화하는 방법은 무엇입니까?
를 넣을 를 했습니다.android: background = "white"
잘만을 때,night mode
한 번만 움직여도 애플리케이션이 엉망이 되고, 모든 것이 백 앤 화이트 무비로 바뀝니다.
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/COLOR_PRIMARY</item>
<item name="colorPrimaryDark">@color/COLOR_PRIMARY</item>
<item name="colorAccent">@color/COLOR_PRIMARY</item>
<item name="cardViewStyle">@style/CardView</item>
<item name="android:fontFamily">@font/helvetica</item>
</style>
저의 원색은 빨간색입니다.
을 의 수 onCreate
실행기 활동 방법.
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
샤오미 노트 8 Pro MIUI 12.0.2 Android 10을 사용하여 테스트했습니다.
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
.MainActivity.onCreate();
하지 않는 것 .
작업 솔루션은 다음을 추가하는 것이었습니다.<item name="android:forceDarkAllowed">false</item>
n 안에AppTheme
styles.xml
예:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
Input Method Service 업데이트:
위해서InputMethodService
Service
에 있을 때 발견했습니다.Dark Mode - Xiaomi MIUI 12.0.3
블랙 컬러가 화이트 컬러로 반전되어 있어요.
.InputMethodService
.
앳.onCreate()
전에super.onCreate()
다라고 부릅니다.
getApplication().setTheme()
setTheme()
를 .Light Theme (Theme.MaterialComponents.Light.NoActionBar)
이 있는.android:forceDarkAllowed=false
.
같은 는.InputMethodService
tgetApplication().setTheme()
반전을 방지하기에 충분하지 않습니다.
in themes.xml change:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
로.
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.DarkActionBar">
반응 네이티브, 이온성(코르도바, 콘덴서)
실제로 이 답변은 특히 React Native 개발자/앱을 위한 것입니다.
우리 모두가 알고 있는 것처럼, 어두운 모드는 안드로이드 10에서 완전히 사용할 수 있습니다.
Android 10(API 레벨 29) 이상에서 다크 테마 사용 가능
그리고 이 기능이 SVG, 글꼴, 배경색과 같은 앱 디자인 구현을 망쳤을 가능성이 높습니다.만약 당신이 완전히 비활성화하기로 결정했다면force dark mode
다음 방법을 따라야 합니다.
당신의 안에 다음 코드를 추가합니다.
<style>
꼬리에 꼬리를 물다styles.xml
일:<item name="android:forceDarkAllowed">false</item>
참고: 파일 경로:
android/app/src/main/res/values/styles.xml
1단계를 마치면 다음과 같은 내용이 나타납니다.
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> ... <item name="android:forceDarkAllowed">false</item> </style> </resources>
아마도 위의 단계들은 당신에게 도움이 되지 않을지도 모르지만 걱정하지 마세요, 이 게시물의 상단에 언급된 것처럼, 이 기능은 API 레벨 29에서 공개됩니다, 이것은 당신이 다음을 변경해야 한다는 것을 의미합니다.
compileSdkVersion
29세 이상.compileSdkVersion
해야 합니다.compileSdkVersion
appradle 속성들은 존재했습니다.android/app/build.gradle
일:android { compileSdkVersion 29
어쩌면 당신은 마주할지도 모릅니다.
compileSdkVersion rootProject.ext.compileSdkVersion
, 걱정하지 마세요 당신은 안드로이드 그라들 속성에서 이것을 바꿔야 합니다.android/build.gradle
일:buildscript { ext { buildToolsVersion = "SomeVersion" minSdkVersion = SomeVersion compileSdkVersion = 29 // <======= this should be 29 or higher targetSdkVersion = SomeVersion
힌트: 새 빌드가 있는지 확인하려면 다음을 사용하여 마지막 빌드를 완전히 삭제합니다.rm -rf android/app/build
에뮬레이터/장치합니다를 합니다.yarn android
시.
액티비티 레크리에이션을 피하려면 여기에 언급된 대로 Application 클래스에 플래그를 설정할 수 있습니다.
애플리케이션 클래스(있는 경우)에 다음과 같이 설정하는 것을 권장합니다.
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
Ali Rezaiyan이 제안한 것은 앱 전체에서 야간 모드를 비활성화하고 싶다면 진행하는 올바른 방법입니다.
때로는 일부 활동이나 단편에서만 야간 모드를 사용하지 않도록 설정해야 할 때도 있습니다(아마도 레거시 항목 때문일 것입니다).
따라서 수행할 작업을 선택할 수 있습니다.
앱 전체 사용 안 함:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
단일 활동에 대해 사용 안 함:
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
- 를 하고 입니다에 할 것입니다.
recreate()
이 효력을
이것은 나에게 효과가 있었습니다 (2021년 4월)
- 테마 아래에 이 줄을 추가합니다.
<item name="android:forceDarkAllowed" tools:targetApi="q"> false </item>
- delete themes.xml (night) 파일(값 폴더 아래)
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
두 테마를 모두 변경합니다. Day Night을 Light로 변경합니다.
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.DarkActionBar">
는 <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
.<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
.
:android/app/src/main/res/values/styles.xml
모든 코드:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
</style>
아래 코드를 사용하지 마십시오.
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
이렇게 하면 활동이 두 번 호출됩니다.
간단히 사용
테마 파일에
먼저 스타일 부모를 가벼운 것으로 만들기
Theme.MaterialComponents.Light.NoActionBar
그런 다음 스타일 아래에 이 선을 추가합니다.
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
당신의 코드는 이렇게 생겼군요.
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/primary_color_app</item>
<item name="colorPrimaryVariant">@color/status_bar_color</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
<!-- Customize your theme here. -->
</style>
참고: Android studio 업데이트 버전이 있는 경우 Night Theme의 스타일을 동일하게 만들어야 합니다.
강제 다크를 비활성화할 활동 레이아웃에서 다음 속성을 상위 레이아웃에 배치합니다.
android:forceDarkAllowed="false"
레이아웃은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:forceDarkAllowed="false">
<!-- ..... -->
</androidx.constraintlayout.widget.ConstraintLayout>
프로젝트(themes.xml)에서 아래의 몇 가지 변경 사항만 수정하십시오.
Android 스튜디오에 최신 버전이 있는 경우 "themes.xml"과 "themes.xml(밤)" 모두에 적용합니다.
변경 사항:
<style name="Theme.demo" parent="Theme.MaterialComponents.DayNight.NoActionBar">`
받는 사람:
<style name="Theme.demo" parent="Theme.MaterialComponents.Light.NoActionBar">
그다음에 아래 행을 추가하면 됩니다.
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
Application class를 상속하는 기본 Application class를 생성하고 create 메서드의 재정의 내부에 다음 줄을 넣습니다. -
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
안드로이드 매니페스트에 이 이름표를 추가하는 것도 잊지 마세요.
다크 모드 비활성화 parent="를 위해 parent로 사용합니다."Theme.AppCompat.라이트.노액션바
styles.xml 파일에서 DayNight를 Light in AppTheme로 변경합니다.
추가하기만 하면 됩니다.AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
super.onCreate(savedInstanceState);
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
당신의 테마에서.
가서 추가:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
단말기에서 다크 모드가 활성화되어 있더라도 테마에서.응용프로그램에 라이트 테마가 적용됩니다.
저는 많은 해결책을 검토했지만 "res" 폴더에서 "values-night" 폴더를 제거하기 전까지는 어떤 것도 강력하지 않았습니다.
And change use parent theme: <style name="Theme.CryptoKite" parent="Theme.MaterialComponents.Light.DarkActionBar">
이 코드 줄은 제게 적합합니다.
<!--To disable dark mode-->
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
다음 줄을 사용하면 앱에서 다크 모드를 오버로드하지 않는 데 도움이 됩니다.
android:forceDarkAllowed="false"
사용 예시,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF"
android:forceDarkAllowed="false"
tools:context=".SplashActivity">
Cordova 전용 개발자를 위한 또 다른 옵션:
출처: https://developer.android.com/guide/webapps/dark-theme
"WebView는 미디어 쿼리의 존재만으로 구별할 수 없기 때문에 웹 페이지에 어두운 테마가 있다는 것을 나타내는 어두운 값을 가진 색상 구성 메타 태그가 필요합니다.더블 다크닝(즉, 미디어 쿼리 사용자 정의 위에 색 반전을 적용하는 것)을 방지하기 위해 WebView는 이 모드에서 @media(기본 설정-색상-방식: 어둡게)를 false로 평가합니다."
그래서 덧붙였어요.<meta name="color-scheme" content="dark">
나의 html과 presto - 이제 내 선호 색상 scheme를 감지합니다. 다크 쿼리를 감지하고 자동 다크닝을 적용하지 않습니다.
IMS 파트에 대한 파우지 다나르타의 답변 외에도.테마를 확장할 수 있습니다.
<item name="android:forceDarkAllowed" tools:targetApi="q"> false </item>
재료 디자인의 테마가 아닌android:Theme.DeviceDefault.InputMethod
(대상 Sdk 버전 14 이후).
통화도getApplication().setTheme()
꼭 필요한 것은 아니고, 단지setTheme()
충분합니다.
MIUI 12.0.4에서 확인했습니다.
나는 덧붙여야만 했습니다.<item name="android:forceDarkAllowed">false</item>
Theme.App.SplashScreen
스타일 또한 엑스포 베어를 사용하고 있습니다.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
<item name="android:forceDarkAllowed">false</item>
</style>
<style name="Theme.App.SplashScreen" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually -->
<item name="android:windowBackground">@drawable/splashscreen</item>
<item name="android:forceDarkAllowed">false</item>
<!-- Customize your splash screen theme here -->
</style>
</resources>
이 코드를 추가하지 않음:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
oncreate Method of Main Activity에 입력하면 oncreate 메소드가 두번 호출됩니다!!!이 줄을 추가하는 것이 문제를 일으켰다는 것을 알아내는 데 한 시간이 걸립니다!
style.xml에 이 줄을 추가하면 됩니다.
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
제 코드에는 이렇게 나와있습니다.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
밝은 테마와 어두운 테마를 모두 같은 색으로 변경합니다.장치가 다크 모드에 있더라도 출력에 영향을 주지 않습니다.
다 안에value/theme.xml
그리고.night/theme.xml
다음 행 변경
<style name="Theme.Labmuffles" parent="Theme.MaterialComponents.DayNight.NoActionBar">
로.
<style name="Theme.Labmuffles" parent="Theme.MaterialComponents.Light.NoActionBar">
앱은 다크 모드이지만 다크 모드에서도 라이트 모드의 색상을 표시하고 항상 라이트 상태를 유지합니다.
저는 코트라인을 쓰고 있습니다.저의 경우 아래 oncreate 방법에 다음과 같은 줄을 추가하였습니다.
활동반에서 그리고
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
value-> style->테마/스타일 클래스, 다음 코드 추가
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:forceDarkAllowed" tools:ignore="NewApi">false</item>
</style
에.<item name="android:forceDarkAllowed">false</item>
styles.xml
,오에서 .
Theme.AppCompat.DayNight.NoActionBar
로.
Theme.AppCompat.Light.NoActionBar
앱 , cd android && ./gradlew clean
잘 작동할 겁니다
테마 폴더에서 다크 모드 테마를 삭제하는 것만으로도 효과가 있었습니다.
간단히 변경
<style name="YourThemeName" parent="Theme.MaterialComponents.DarkActionBar">
로.
<style name="YourThemeName" parent="Theme.AppCompat.Light.DarkActionBar">
테마와 테마 둘다 밤에
그리고 테마와 테마의 밤에 모든 색깔이 같은지 확인합니다.
레드미노트 7 프로에 포스 나이트 모드 문제가 있습니다.그런데 제가 사용할 때.
AppCompat 대리인.기본 야간 모드(AppCompatDelegate)를 설정합니다.MODE_NIGHT_NO);
저의 어플리케이션 레벨 수업에서 이 방법과 전체 앱 테마가 라이트 테마로 바뀌었지만 사실 저도 나이트 테마를 원했습니다.
그리고 다음과 같은 특정 관점에 대한 해결책을 찾았습니다.
안드로이드:forceDarkAllowed="false"
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white_black"
android:elevation="@dimen/dim4"
android:forceDarkAllowed="false"
android:forceHasOverlappingRendering="false"
app:itemIconTint="@drawable/highlighted_bottom_nav_item"
app:itemTextAppearanceActive="@style/BottomNavigationView.Active"
app:itemTextAppearanceInactive="@style/BottomNavigationView"
app:itemTextColor="@drawable/highlighted_bottom_nav_item"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_nav_menu" />
그냥 고쳤어요.
언급URL : https://stackoverflow.com/questions/57175226/how-to-disable-night-mode-in-my-application-even-if-night-mode-is-enable-in-andr
'programing' 카테고리의 다른 글
WooCommerce - 사용자 지정 썸네일 및 기본 폴백 이미지 자리 표시자 (0) | 2023.10.07 |
---|---|
Oracle SQL에서 정규식과 일치하는 문자열의 일부를 가져오는 방법 (0) | 2023.10.07 |
int 배열에 대한 포인터에 대한 스칼라 이니셜라이저의 초과 요소 (0) | 2023.10.07 |
WSO2 ESB5.0.0에서 데이터베이스 및 레지스트리 인덱싱과 관련된 WARN 가져오기 (0) | 2023.10.07 |
div 클릭 시 fireing focus 이벤트 방지 (0) | 2023.10.07 |