我 2 个月前开始在学校使用 Android Studio,但在使用 FloatinActionButton 时遇到了一些问题。即使我正在使用支持库,它也不会显示在 KitKat 中。
这是我的 Activity 的 XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.leonardoguerrag.budget.MainActivity"
android:clipToPadding="true"
android:paddingBottom="0dp"
android:background="@android:color/holo_orange_light">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:fabSize="mini"
app:srcCompat="@android:drawable/ic_menu_compass"
android:id="@+id/btnAgregarGasto"
app:layout_constraintBottom_toTopOf="@+id/btnAgregar"
android:layout_marginBottom="16dp"
app:layout_constraintLeft_toLeftOf="@+id/btnAgregar"
app:layout_constraintRight_toRightOf="@+id/btnAgregar" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:fabSize="mini"
app:srcCompat="@android:drawable/ic_input_get"
android:id="@+id/btnAgregarBudget"
app:backgroundTint="?attr/colorPrimary"
app:layout_constraintBottom_toTopOf="@+id/btnAgregarGasto"
android:layout_marginBottom="16dp"
app:layout_constraintLeft_toLeftOf="@+id/btnAgregarGasto"
app:layout_constraintRight_toRightOf="@+id/btnAgregarGasto" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:fabSize="normal"
app:srcCompat="@android:drawable/ic_input_add"
android:id="@+id/btnAgregar"
app:backgroundTint="@android:color/holo_blue_dark"
app:layout_constraintBottom_toBottomOf="@+id/viewPager"
android:layout_marginBottom="16dp"
app:layout_constraintRight_toRightOf="@+id/viewPager"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" />
<android.support.design.widget.TabLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:tabMode="fixed"
android:id="@+id/tabLayout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="0dp"
android:id="@+id/viewPager"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/tabLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0">
</android.support.v4.view.ViewPager>
我的依赖项:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
}
它在 Marshmallow 和 Nougat 中按预期工作,可能在 Lollipop 上也如此。
我不知道我错过了什么。
我调查了this ,但找不到答案。
谢谢!
最佳答案
不知何故,按钮显示正确,但位于 ViewPager 的背面。
在我的 onCreate() 函数中,我刚刚添加了 .bringToFront();在我所有的 FAB 上,它们现在都可见!
例如。
FloatingActionButton btnAgregar;
btnAgregar = (FloatingActionButton) findViewById(R.id.btnAgregar);
btnAgregar.bringToFront();
关于java - FloatingActionButton 在 KitKat 上不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39987503/