android - 使用 FragmentScenario 时的样式问题
问题描述
使用FragmentScenario
fromandroidx.fragment:fragment-testing
测试片段 UI 时,并非所有样式都正确应用。
例如,有一个非常简单的应用程序,它只显示具有以下布局的片段:
fragment_main.xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Hello World!"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
使用 Android Studio (4.1.2) 生成的默认主题,在运行应用程序时如下所示:
作为FragmentScenario
测试运行时看起来不一样:
我可以理解ActionBar
没有显示(因为它是 hostActivity
而不是 a的一部分Fragment
)。但是为什么Button
样式不正确...??
解决方案
推荐阅读
- visual-studio - TFVC 如何管理“获取最新版本”和挂起的更改?
- reactjs - 样式 div 彼此相邻和重叠
- regex - 使用正则表达式从文件中删除记录
- c++ - shared_ptr use_count() 在赋值运算符 (=) 后返回 0
- linux - 在@INC 中找不到 Mojo/DOM.pm(您可以安装 Mojo::DOM 模块)(@INC 包含:/etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30. 2)
- python - 我使用 LSTM 预测黄金价格,但输出始终是相同的值。有谁知道问题?
- html - 将带有嵌套块引用的电子邮件 HTML 转换为电子邮件的纯文本(pandoc)?
- python - Python networkx:显示一个节点的不同颜色
- java - 使用 maven 插件下载具有依赖关系的特定 jar
- webgl - 在 WebGL 中调试