我有一个问题。我正是需要这个工具栏。
工具栏标题必须居中,向上按钮的颜色必须与标题颜色不同。例如,我可以使用这些代码行实现居中标题。
<androidx.appcompat.widget.Toolbar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="?attr/actionBarTheme"
android:minHeight="?attr/actionBarSize"
android:id="@+id/tb_main"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/tb_title_main"
android:textColor="@color/black_80"
android:textSize="20sp"
/>
</androidx.appcompat.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
这是在我的 MainActivity
val toolbar = binding.tbMain
toolbar.tb_title_main.text = "Centered Text "
setSupportActionBar(toolbar)
supportActionBar?.setDisplayShowTitleEnabled(false)
Run Code Online (Sandbox Code Playgroud)
但我想要使用 Jetpack 导航组件设置工具栏,以便更好、更轻松地导航。当我在 MainActivity 中使用这些代码行设置工具栏时,就会发生这种情况。
val navController = findNavController(R.id.nav_host_fragment)
val toolbar = binding.tbMain
setSupportActionBar(toolbar)
val appBarConfiguration =
AppBarConfiguration(navController.graph)
toolbar.setupWithNavController(navController,
appBarConfiguration)
Run Code Online (Sandbox Code Playgroud)
https://ibb.co/6v8PPmR(另一张图片)
我花了将近 4 个小时来处理这些。我尝试了很多解决方案,但没有任何效果。
因此,使用 setupWithNavController 时可以将工具栏中的文本居中还是我应该提出自己的自定义解决方案?
我正在尝试在我的应用程序中打开一个 TWA 并且已经研究了 2 天。
我已经设法创建了一个 TWA 应用程序,不用大惊小怪,只需编辑清单和其他一些东西。
现在我需要拥有自己的应用程序 - 假设该应用程序首先有一个闪屏活动,然后在应用程序内打开 TWA。例如,我可以通过简单的启动屏幕活动在我的应用程序中启动 TWA 吗?
我确实尝试过使用CustomTabs方式,但它说它已被弃用并改为使用TrustedWebActivityIntentBuilder,但我重复一遍,关于如何使用它的零文档!
Android 开发文档很糟糕。除其他外,文档指针已过时。(阅读他们频道上的视频,这些视频链接到对视频本身讨论的内容不再有效的指南)
我发现最接近的是这个示例项目。这使用了大量已弃用的东西,使将该方法适应我的应用程序完全无用。它还利用了为该项目创建的无数自定义类/帮助程序,让我进行了一场永无止境的马拉松式复制粘贴每一个只是为了发现在那个里面还有更多需要复制到项目。
我有一个消息列表。每条消息都有一个唯一的 GUID。
我的设置适用于正常使用:用户单击对话,列表将打开,其中包含属于该对话的所有消息,按最新的顺序排列。
对话片段
@Override
public void onViewCreated(
@NonNull View view,
@Nullable Bundle savedInstanceState
) {
LifecycleOwner lifecycleOwner = getViewLifecycleOwner();
viewModel = new ViewModelProvider(this).get(ConversationViewModel.class);
viewModel
.getMessageList(lifecycleOwner, conversationId) // conversationId is a global variable
.observe(lifecycleOwner, messagePagingData -> adapter.submitData(
lifecycleOwner.getLifecycle(),
messagePagingData
));
super.onViewCreated(view, savedInstanceState);
}
Run Code Online (Sandbox Code Playgroud)
对话视图模型
final PagingConfig pagingConfig = new PagingConfig(10, 10, false, 20);
private final ConversationRepository conversationRepository;
public ConversationViewModel(@NonNull Application application) {
super(application);
conversationRepository = new ConversationRepository(application);
}
public LiveData<PagingData<ItemMessage>> getMessageList(
@NonNull LifecycleOwner lifecycleOwner,
@NonNull String conversationId
) {
return …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用数据绑定将点击侦听器设置为布局文件中的LinearLayout视图.xml。
我设法使它在诸如Button或的其他视图上可以很好地工作TextView,但是由于某种原因,它不能与一起使用LinearLayout。
这是我尝试的基本内容,但我仍然无法使它起作用:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:clickable="true"
android:focusable="true"
android:onClick="@{action::linearLayoutClicked}"
android:orientation="vertical">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
linearLayoutClicked我的方法在动作类中定义在哪里:
public void linearLayoutClicked(View view) {
// specific logic
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用子视图,并使用clickable和focusable设置为false以及duplicateParentState将true和设置为false。
该操作与在其他视图上正常使用的操作完全相同。
这是错误还是我做错了?为什么这不起作用,LinearLayout但对于其他视图却没有任何问题呢?
我有一个包含一组链接的div,我的目标是按内容自动对这些链接进行排序,请按照下面的示例进行更好的理解:
之前
<div id="sort-this-div">
<a href="http://something45yer.com">Content3</a>
<a href="http://somethingeyerty.com">Content1</a>
<a href="http://somethingfwegrw.com">Content2</a>
<a href="http://somethingt43rwer.com">Content4</a>
</div>
Run Code Online (Sandbox Code Playgroud)
后
<div id="sort-this-div">
<a href="http://somethingeyerty.com">Content1</a>
<a href="http://somethingfwegrw.com">Content2</a>
<a href="http://something45yer.com">Content3</a>
<a href="http://somethingt43rwer.com">Content4</a>
</div>
Run Code Online (Sandbox Code Playgroud) 我在这里试图解决这个问题.我已经编写了一个jquery函数,用于检测用户何时触及页面底部并触发函数.现在,虽然这对于最常见的屏幕尺寸来说是正常的,但是当用户的屏幕太大以至于一次看到整个页面时,它将无法工作,从而使之前的功能无效.
我想要实现的是这些情况的后备,如何判断用户是否具有触发该功能的屏幕尺寸并将其余部分留给另一个?
更好的解释:如何检测用户浏览器高度是否等于或大于页面主体高度?
对不起,如果这看起来有点令人困惑.
PS:当浏览器高度小于页面高度时,以下代码是我正在使用的代码.
if ($('body').height() <= ($(window).height() + $(window).scrollTop())) {
//run function here when the browser-height is smaller than
//the page's height and it has reached the bottom
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试ConstraintLayout结合使用与动画上下滑动的视图。这些视图是垂直组织的,RecyclerView顶部是,下面是其他两个视图:
<constraint layout container>
[ ]
[ recycler view ]
[ ]
[48dp height 1st view]
[48dp height 2nd view]
</constraint layout container>
Run Code Online (Sandbox Code Playgroud)
动画非常简单:轻按一个按钮时,第一个视图从容器的底部移到您可以在上方看到的位置,再次轻击时,它向下移动并在第二个视图上保持重叠。发生这种情况RecyclerView时,顶部会更改高度,因为它会受限于该第一个视图,否则它将留出空白空间。
到目前为止,效果很好,动画效果良好,但是当用户过快地点击按钮时会出现问题,从而导致以下错误:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Run Code Online (Sandbox Code Playgroud)
在调查了发生了什么之后,我发现这个问题是由于TransitionManager我正在使用动画制作更改的结果。我发现的很有趣,当点击按钮以将第一个视图上移(或下移,想象一下相反的步骤)时,经理正在执行以下操作:
RecyclerView(取决于您是否启用了反向布局或从头到尾堆叠)RecyclerViewRecyclerView即使我在所有位置都指定了位置,我也可以想象RecyclerView不应该为项目更改设置动画,但是TransitionManager覆盖了它,这意味着当即将要从中移除的同一视图RecyclerView可以再次添加到同一视图时,存在一个窗口父窗口,而该窗口就是管理器正在淡出视图的时间。
由于淡入淡出的动画速度不是那么快,因此用户可以在这段时间内非常轻松地轻按两次按钮,从而使管理者重新添加已经存在的淡入淡出视图,RecyclerView从而在抛出上述错误时使应用程序崩溃。
由于这是内部引起的问题RecyclerView,因此在其中没有动画的情况下我会很好,因此,我想知道如何在中指定TransitionManager.beginDelayedTransition仅对的直接子视图进行动画处理ConstraintLayout,这样就不会对进行动画处理里面的景色RecyclerView。
相关文档对此没有任何帮助,因此在此提出这个问题。如何限制过渡到直接子视图?
如果这可能会有所帮助,请在此处包括过渡管理器的代码段 …
我有一个带有 Android Studio 中默认布局的工具栏的活动,我可以通过以下方法轻松更改工具栏中的标题:
Bundle bundle = new Bundle();
bundle.putString("toolbarTitle", "A new title");
NavHostFragment
.findNavController(this)
.navigate(R.id.action_navigation_conversation_to_placeholder, bundle);
Run Code Online (Sandbox Code Playgroud)
toolbarTitle导航菜单布局中已经实现了安全参数。
但是现在我尝试更改通过上述方法打开的片段的标题,例如;
我的活动->打开->我的片段
MyFragment 更改标题
我确实知道如何在不使用导航 UI 组件的情况下更新它,但如果可能的话我想使用它们。
其他类似的问题仅与我上面提供的示例有关,即打开新片段时或建议使用不使用导航 UI 组件的典型方法,没有一个涵盖此特定场景。
android android-titlebar android-navigation android-components