我一直在将新的(ish)材质 BottomAppBar 与标准的底部导航视图相结合。我的xml是这样的:
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:fabAlignmentMode="center">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="@android:color/transparent"
app:itemTextAppearanceActive="@style/AppTheme.Text.BottomNavText.Active"
app:itemTextAppearanceInactive="@style/AppTheme.Text.BottomNavText"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_nav_menu" />
</com.google.android.material.bottomappbar.BottomAppBar>
Run Code Online (Sandbox Code Playgroud)
在以前的版本 - 1.0.0 - 这工作正常,我仍然可以按预期看到 FAB 插图。唯一的小缺点是这个版本的材质组件库没有对底部应用栏的高度效果进行排序,所以栏和上面的内容之间的区别并不明确。
当我升级到最新的库(在撰写本文时我相信是)时implementation 'com.google.android.material:material:1.1.0-alpha09'
,我得到了 BottomAppBar 的高度效果,但是当我将透明背景应用到 BottomNavigationView 时,我得到了一个非常奇怪的视觉效果,对于我的生活我不能理解。
如果我删除透明背景颜色,那么效果会消失,但我会丢失 FAB 插图,如下所示:
如果我完全删除底部导航视图子项,并且只有底部应用栏,我会看到正常的视觉效果,但没有我的导航:
我会喜欢: - 一个很好的解决方案,将底部导航视图合并到 BottomAppBar 中,同时保留 1.1.0 版库的良好提升效果,并且在其中有效地包含 BottomNavigationView,因此我保留了该导航组件的所有优点 - 或解释到底是什么导致了这种奇特的第一次海拔效应,理想情况下是一种修复它的方法
android material-design bottomnavigationview material-components bottomappbar
我有一个模块化的项目,其中 api 层被分成自己的模块。由于它不依赖于 Android SDK,因此我将其设为 kotlin 专用模块。这具有 kotlin jvm 插件,如下所示在构建文件中。当我尝试使用 MockWebServer 时,这会导致 java.lang.NoSuchFieldError: Companion 错误(仅此,其他一切正常)。
在构建文件中使用 kotlin dsl,build.gradle.kts 文件如下所示:
plugins {
kotlin("jvm")
kotlin("kapt")
}
dependencies {
implementation(kotlin("stdlib"))
implementation("com.squareup.retrofit2:retrofit:2.7.0")
implementation("com.squareup.retrofit2:converter-moshi:2.7.0")
implementation("com.squareup.moshi:moshi-kotlin:1.9.2")
implementation("com.squareup.okhttp3:logging-interceptor:4.4.0")
testImplementation("com.squareup.okhttp3:mockwebserver:4.4.0")
testImplementation("junit:junit:4.13")
kapt("com.squareup.moshi:moshi-kotlin-codegen:2.7.0")
// There are various other libraries, but I'm including the only ones I feel are relevant
// in case my problem is to do with conflicting versions of libraries
}
Run Code Online (Sandbox Code Playgroud)
这是我的单元测试的片段。我实例化 MockWebServer() 的行因 NoSuchFieldError: Companion 失败:
class LoginServiceTest {
private val mockWebServer: MockWebServer = MockWebServer()
Run Code Online (Sandbox Code Playgroud)
和堆栈跟踪: …
假设我有一个'用户'的集合,我很高兴他们的ID成为生成的Firestore documentId,如下所示:
Users Collection
GENERATED_FIRESTORE_ID1:
name: "User 1 name"
...: etc.
GENERATED_FIRESTORE_ID2:
name: "User 2 name"
...: etc."
Run Code Online (Sandbox Code Playgroud)
我正在添加它们,并使用自定义对象检索它们(我现在使用的是Android,但我猜的问题更为通用).我不想在文档中有一个额外的"id"字段,只需使用该document.getId()
方法来获取生成的firestore ID.
是否有正确的方法将POJO映射到没有单独的ID字段,但在查询时将其设置为应用程序使用情况?我正在使用@Exclude注释进行如下操作:
public class User {
// as a side question, do I need @exclude on the field or just the getter?
@Exclude
String uId;
String name;
String email;
//... additional fields as normal
public User() {
}
@Exclude
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() { …
Run Code Online (Sandbox Code Playgroud) 我需要在 NumberPicker 中获取对 EditText 的引用。我知道它会是选择器视图本身的某种 findViewById,但我一直无法为它找到 android 的 id:
final NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.numberpicker);
EditText numberPickerEditText = (EditText) numberPicker.findViewById(WHAT IS THE ID???)
Run Code Online (Sandbox Code Playgroud)
我知道 NumberPicker 具有大多数有用的值等方法,但我需要一些更精细的控制,例如在选择器打开时显示键盘,我认为如果没有对 EditText 本身的引用,我无法做到这一点(随意如果我错了,请纠正我!)