简体   繁体   English

导航喷气背包组合不能直接工作

[英]Navigation jetpack compose doesn't work directly

I have a problem with Navigation jetpack compose, the problem is navigation doesn't work directly and shows an empty screen, but if I scroll in the empty screen or do a long click after that navigation starts working and shows the screen that I put inside the navigation.我的 Navigation jetpack compose 有问题,问题是导航不能直接工作并显示空屏幕,但是如果我在空屏幕中滚动或在导航开始工作并显示我放入的屏幕后长按导航。

I search a lot about this problem and I don't find any solution.我搜索了很多有关此问题的信息,但找不到任何解决方案。

I try to change the version of the navigation compose and all the versions don't work.我尝试更改导航组合的版本,但所有版本都不起作用。 and also when I use dark them work with out problme而且当我使用深色时,它们也可以毫无问题地工作

except for version "2.4.0-alpha10" which works in some projects and doesn't in some projects除了版本“2.4.0-alpha10”在某些项目中有效而在某些项目中无效

what is the problem?问题是什么? and why does this happen?为什么会这样?

build.建造。 gradle (Medule:app) gradle(模块:应用程序)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.example.myapplication'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.3.2'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.5.1'
    implementation platform('androidx.compose:compose-bom:2022.10.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-tooling'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'

    def nav_version = "2.5.3"

    implementation "androidx.navigation:navigation-compose:$nav_version"
}

build.建造。 gradle (project) gradle(项目)

plugins {
    id 'com.android.application' version '8.1.0-alpha02' apply false
    id 'com.android.library' version '8.1.0-alpha02' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}

Main Actvity主要活动

package com.example.myapplication

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    val navController = rememberNavController()
                    NavHost(navController = navController, startDestination = "younes") {
                        composable("younes") {
                            Text(text = "younes")
                        }
                    }
                }
            }
        }
    }
}

go to the Theme.file and change this line. go 到 Theme.file 并更改此行。

WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme

to

WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = true WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = true

just change darkTheme to true只需将 darkTheme 更改为 true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM