我试图仅在几个片段中显示底部栏导航(即在大部分片段中隐藏它)。
我阅读了有关此内容的官方文档,但我不清楚,比如我应该将代码放在哪里,并且我在 StackOverFlow 上阅读了对此的评论,例如“我很惊讶文档中建议这样做,因为它实际上看起来非常糟糕因为侦听器在新片段放置在屏幕上之前触发,导致可见的闪烁(有时存在,有时不存在) ”。
我对此进行了研究,根据我的理解,我需要创建一个嵌套的 naviagtion_graph (导航)或其他东西,听 onDestinationChanged 并将底部导航或工具栏设置为 Gone..
我不太明白这一点..我只是想隐藏大多数片段中的底部栏导航..
这是我的 navigation_gragh ( mobile_navigation) :
<navigation 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:id="@+id/mobile_navigation"
    app:startDestination="@+id/navigation_home">
    <fragment
        android:id="@+id/navigation_home"
        android:name="com.example.testingbottomnav.ui.home.HomeFragment"
        android:label="@string/title_home"
        tools:layout="@layout/fragment_home" >
        <action
            android:id="@+id/action_navigation_home_to_newScreenFragment"
            app:destination="@id/newScreenFragment" />
    </fragment>
    <fragment
        android:id="@+id/navigation_dashboard"
        android:name="com.example.testingbottomnav.ui.dashboard.DashboardFragment"
        android:label="@string/title_dashboard"
        tools:layout="@layout/fragment_dashboard" />
    <fragment
        android:id="@+id/navigation_notifications"
        android:name="com.example.testingbottomnav.ui.notifications.NotificationsFragment"
        android:label="@string/title_notifications"
        tools:layout="@layout/fragment_notifications" />
    <fragment
        android:id="@+id/newScreenFragment"
        android:name="com.example.testingbottomnav.ui.newscreen.NewScreenFragment"
        android:label="fragment_new_screen"
        tools:layout="@layout/fragment_new_screen" />
</navigation>
Run Code Online (Sandbox Code Playgroud)
这是我的activity_main.xml:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize">
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:labelVisibilityMode="selected" …Run Code Online (Sandbox Code Playgroud) android android-fragments kotlin bottomnavigationview android-bottomnav
我正在尝试制作一些使用与下图相同概念的东西;
类似背景的图像,上面有文字。
我尝试制作一张卡片并为其指定图像的背景颜色,但出现错误;
我想要做的是在图像上覆盖一些文本,如上图所示。
那么请问我该如何安排这段代码。我需要将所有内容都放在一个可组合项中,因为我需要填充它。
提前感谢您的理解和帮助。
请,我很乐意提供所需的更多信息。
android android-jetpack android-jetpack-compose android-compose-textfield
几天前我正在做一个项目,该项目已保存并关闭,但MainActivity今天打开时出现错误。
错误:无法访问“androidx.core.app.ComponentActivity”,它是“com.careerinfluencer. Fivehundreddays.MainActivity”的超类型。检查模块类路径是否缺少或冲突的依赖项
我什至不知道要检查的模块类路径,也不知道这里要包含什么。
但我只是要添加一些文件AndroidManifest。
Android 清单:
<application
    ...
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:theme="@style/Theme.FiveHundredDays">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
Run Code Online (Sandbox Code Playgroud)
这是这样的图像error:
我刚刚注意到 AndroidManifest 文件中也出现错误。.MainActivity准确地说是在活动中。
错误:MainActivity 必须扩展 android.app.Activity
这是这样的图像error:
我真的很感激并欢迎任何关于如何解决这个问题的想法。
在此先感谢您的帮助。
android-manifest android-activity kotlin android-jetpack-compose
我是 kotlin 新手,正在练习基础知识。每当我运行一个简单的代码时,它都会拒绝运行,然后我会得到一个
Execution failed for task ':app:processDebugAndroidTestManifest'.
> Manifest merger failed with multiple errors, see logs
Run Code Online (Sandbox Code Playgroud)
错误。
我不知道原因是什么,请注意我实际上正在运行一个print("Hello")函数
这是我的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.hellokotlin">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.HelloKotlin">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
这是我的gradle.build:
plugins {
    id 'com.android.application'
    id 'kotlin-android'
}
android {
    compileSdk 31
    defaultConfig {
        applicationId "com.example.hellokotlin"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes …Run Code Online (Sandbox Code Playgroud) android-manifest kotlin android-studio android-gradle-plugin
我正在尝试实现 onClickListener 来recyclerView打开一个新的片段,我知道它们在 stackoverflow 上已经很多了,但作为初学者,我发现它们有些复杂。
就像我说的,我想在点击时打开一个片段recyclerView,我有一些问题;
主要是我该怎么做??
如何控制我导航到的屏幕的视图(即文本视图、图像视图等)?
这是具有 recyclerView 的片段
class NewScreenFragment : Fragment() {
    private var _binding: FragmentNewScreenBinding? = null
    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!
    // for the recyclerView
    private lateinit var newArrayList: ArrayList<DataClass>
    // variables to the recyclerView views
    lateinit var imageId: Array<Int>
    lateinit var title: Array<String>
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? { …Run Code Online (Sandbox Code Playgroud) 总之,我想根据单击的项目导航到目的地。
但问题是我创建这些项目的方式,这是我不知道如何隔离项目并为它们提供 onClick 函数的方式。
附言。我使用数据类和对象函数来制作项目;
data class MenuData(
    Val id: Int,
    Val title: String,
    val menuImageId: Int = 0
)
Run Code Online (Sandbox Code Playgroud)
object MenuModel {
    .....
    fun menuModelList(context: Context) = listOf(
        MenuData(
            id = 1,
            title = context.getString(R.string.menu_log),
            description = context.getString(R.string.menu_logText),
            menuImageId = R.drawable.menu_log
        ),
      .....
    )
}
Run Code Online (Sandbox Code Playgroud)
通常我所做的导航是(示例代码):
@Composable
fun WaysCard(
    waysInfo: WaysData,
    onWaysCardClick: (Int) -> Unit,
    modifier: Modifier = Modifier
) {
    Surface(
        shape = MaterialTheme.shapes.small,
        elevation = 10.dp,
        modifier = modifier
            .clickable { onWaysCardClick(waysInfo.id) }
    ) 
    ....
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我为可组合项提供了一个单击函数,并将数据类作为参数传递,因为通常这些项目是通用的,它们的大部分内容都以类似的方式排列。 …
android kotlin android-jetpack-navigation android-jetpack-compose jetpack-compose-navigation