android-fragments 相关问题

片段表示Android应用中的可重用行为或用户界面的一部分。

将数据从 Activity 发送到片段的最佳方式是什么

所以我的问题很简单。我有两个活动(splash 和主活动),3 个片段将放置在主活动上。我想从启动屏幕上的 api 获取数据并将获取的数据显示在...

回答 1 投票 0

如何重新加载当前片段而不将其添加到后台堆栈,同时保持同一片段在后台堆栈中先前添加的位置?

我有一个主要活动,其中有一个回收器视图,我从中打开一个新片段,比如说片段1,现在在片段1中我有一个场景,我必须重新加载/替换相同的片段,...

回答 1 投票 0

将 Arryaylist 作为共享首选项保存到 json 后,在 Fragment 中实现 RecyclerView 时遇到问题

我无法显示片段,但我的活动中没有显示任何内容。我的目标是将sharedpreference保存为gson,因为arraylist无法保存到sharedpreference中然后使用gson...

回答 1 投票 0

在Android移动应用程序(Android Studio)的片段中找到一个箭头

我目前正在 Android Studio 中开发一个 Android 移动应用程序,该项目旨在创建一个集中在线或本地玩迷你游戏的应用程序。我的项目正在进行中...

回答 1 投票 0

java.lang.IllegalStateException:键 f0 的片段不再存在:索引 1

我的活动中有几个片段。完成一些过程后,我使用下面的代码关闭片段。 if (getActivity().getSupportFragmentManager().getBackStackEntryCount() > ...

回答 11 投票 0

DialogFragment 忽略 OnBackPressedDispatcher

我正在尝试使用 'androidx.activity:activity-ktx:1.1.0-alpha01' 和 'androidx.fragment:fragment-ktx:1.2.0 处理 BottomSheetDialogFragment 中的后退按钮,这是一个 DialogFragment -alpha0...

回答 5 投票 0

如何解决错误“LifecycleOwners必须在启动之前调用register”

我在开发中使用 registerForActivityResult 进行谷歌登录实现。一切都工作正常,直到我将片段依赖项升级到 1.3.0-beta01。应用程序当前

回答 9 投票 0

将数据从嵌套片段发送到父片段

我有一个片段 FR1,其中包含多个嵌套片段; FRa、FRb、FRc。这些嵌套片段可通过按 FR1 布局上的按钮来更改。每个嵌套片段都有多个输入...

回答 9 投票 0

底部导航如何从片段内部更改片段

我有一个包含 3 个片段的底部导航视图 我想从片段 1 内部而不是从活动中将片段 1 更改为片段 2 有谁知道怎么做吗?

回答 2 投票 0

如何让底部导航Activity通过滑动改变片段?

我使用适当的 android studio 模板创建了一个新活动:新建->活动->底部导航活动。我向 AppBarConfiguration 添加了 5 个片段,除了一个之外一切正常......

回答 2 投票 0

无法使用片段在一个 Activity 中显示两个 XML 布局

我的 Android 项目面临一个问题,我试图在一个 Activity 中显示两个 XML 布局并使用片段在它们之间切换。这是我的设置的细分: 1.活动结构...

回答 1 投票 0

BottonNavigationView 图标在按下后不会改变

我正在使用导航组件作为底部导航组件。 底部导航栏.setupWithNavController(navController) 现在一切正常,但是当我按下后退按钮时,它会返回到...

回答 3 投票 0

从保存的实例恢复片段时如何防止editText自动填充文本?

我有一个保存并显示多个片段的活动。 当我重新输入片段时,它会自动在所有编辑文本中填充文本。所有字段也使用相同的文本。 例子: 打开片段并

回答 3 投票 0

键盘打开时背景图片向上滑动

我在 Android 中构建登录页面时遇到问题。我想将用户名和登录名保留在布局的底部。但是当输入用户名/密码时,键盘会弹出,还有我的背景图片

回答 3 投票 0

开发Android应用程序时如何使用Java中的片段管理器提高片段的加载速度?

我对Android开发还很陌生。我的程序由一个活动和一堆可以通过菜单导航到的片段组成。 有些 Fragments 仅包含 ~12 个 TextView 并加载...

回答 1 投票 0

Recyclerview 未在 ViewPager 内滚动

我有 ViewPager2 和 3 个片段,并且所有片段都有 recyclerview,但在中间片段 recyclerview 中,如果我尝试触摸 recyclerview 项目,则不会滚动,但如果我触摸右或左 si,它会平滑滚动...

回答 2 投票 0

Android 在另一个片段中显示 2 个片段

我有一个带有 MainActivity 和导航抽屉菜单的应用程序。 在 MainActivity 视图中,我有一个占据整个空间的框架布局。 当用户从...中选择某些内容时...

回答 1 投票 0

android:我们应该在 onHiddenChanged 函数中调用 onPause 和 onResume 吗?

我们使用的是没有viewpage的fragment,只需简单地按下按钮隐藏fragment A显示fragment B或显示A隐藏B,就会触发onHiddenChanged()函数 但我们有一个争论...

回答 1 投票 0

防止 Snackbar 与 Activity 子 Fragment 的 ConstraintLayout 中的 FloatingActionButton 重叠

这是我当前的设置: 我有一个在根布局(CoordinatorLayout)上注册小吃栏的 BaseActivity: 这是我当前的设置: 我有一个在根布局(CoordinatorLayout)上注册小吃栏的 BaseActivity: <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/snackbar_container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_dodgeInsetEdges="bottom"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content"> <include layout="@layout/toolbar" /> </com.google.android.material.appbar.AppBarLayout> <include layout="@layout/progressbar_with_text" /> <androidx.fragment.app.FragmentContainerView android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout> 现在我添加一个如下所示的片段: <?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"> <androidx.viewpager.widget.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="0dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="parent" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab_save" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/content_save" android:tint="@android:color/white" android:visibility="gone" app:backgroundTint="@color/secondary" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:tint="@android:color/white" app:useCompatPadding="true" tools:ignore="SpeakableTextPresentCheck" tools:visibility="visible" /> </androidx.constraintlayout.widget.ConstraintLayout> 我希望晶圆厂在显示时被小吃栏推起,目前它与小吃栏重叠。 我知道使用 CoordinatorLayout 作为根并将 FloatingActionButton (FAB) 放置在其中可以与属性 app:layout_dodgeInsetEdges="bottom" 配合使用。此设置可确保在显示 Snackbar 时将 FAB 向上推。但是,对于子片段,我无法获得类似的结果。是的,我的设置必须保持原样,因为我有多个彼此不同的片段,并且包含独特样式的 FAB,因此将 FAB 移动到活动级别不是一个选项。 您应该在 BaseActivity 中创建一个方法来显示小吃栏,在该方法中通过其 id 找到 coordinatorLayout。 public void showSnackbar(String message, int duration) { CoordinatorLayout coordinatorLayout = findViewById(R.id.snackbar_container); Snackbar.make(coordinatorLayout, message, duration).show(); } 你的fragment应该能够访问BaseActivity。确保你的activity实现了某个接口,这将允许fragment与activity进行通信。 public class MyFragment extends Fragment { private BaseActivity activity; @Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof BaseActivity) { activity = (BaseActivity) context; } } private void showSnackbar(String message) { activity.showSnackbar(message, Snackbar.LENGTH_SHORT); } }

回答 1 投票 0

android中如何通过FragmentTabHost播放视频

我制作了一个有 4 个选项卡的应用程序: 视频选项卡,在此选项卡中我想播放视频,获取远程 url 虚拟实验室 编辑视频 帮助 我制作了 MainActivity 类,其中使用 FragmentTabHost

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.