我更改了 android:background 的风格:
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#747474</item>
<item name="colorControlActivated">@color/colorAccentTrans</item>
<item name="colorControlHighlight">@color/colorAccentTrans</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">@color/background</item>
</style>
现在,像我的材料日历视图这样的一些元素似乎有很多可见性,我不知道为什么。
这里是片段布局的 XML:
<RelativeLayout 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"
android:background="@color/background"
tools:context="io.rocketfox.dreamydiary.JournalView">
<android.support.constraint.ConstraintLayout
android:id="@+id/layout_nothingInList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@color/background"
android:padding="0dp"
android:visibility="invisible"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="50dp">
<ImageView
android:id="@+id/img_NoDreamsHint"
android:layout_width="167dp"
android:layout_height="115dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="false"
android:cropToPadding="true"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.39999998"
app:srcCompat="@drawable/sheep" />
<TextView
android:id="@+id/txt_NoDreamsHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="No dreams yet"
android:textColor="@color/splashScreenAction"
android:textSize="24sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/img_NoDreamsHint" />
</android.support.constraint.ConstraintLayout>
<RelativeLayout
android:id="@+id/layout_calendarPicker"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.prolificinteractive.materialcalendarview.MaterialCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mcv_allowClickDaysOutsideCurrentMonth="true"
app:mcv_arrowColor="@color/cardview_light_background"
app:mcv_dateTextAppearance="@style/CustomTextAppearanceDates"
app:mcv_firstDayOfWeek="monday"
app:mcv_headerTextAppearance="@style/CustomTextAppearanceMonth"
app:mcv_selectionColor="@color/colorAccentTrans"
app:mcv_tileSize="40dp"
app:mcv_tileWidth="50dp"
app:mcv_weekDayTextAppearance="@style/CustomTextAppearanceWeek"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="81dp" />
<ListView
android:id="@+id/listDreams"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/calendarView"
android:background="@color/background" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_AddDream"
style="@style/Widget.Design.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@drawable/add" />
</RelativeLayout>
</RelativeLayout>
Fab 按钮是唯一可见的东西。
背景更改后的布局屏幕截图:https://i.stack.imgur.com/RNcAY.jpg
- 在你的风格中,你应该使用
android:windowBackground
而不是android:background
windowBackground
是仅在以下情况下有效的样式属性 样式作为主题应用于Activity
或application
,并且android:windowBackground
属性仅支持对 另一个资源。
- 只显示
FAB
,因为FAB
的容器是一个RelativeLayout
,它的width
和height
match_parent
。这就是为什么它与您的layout_calendarPicker
重叠的原因.
更新布局 XML,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@color/background">
<android.support.constraint.ConstraintLayout
android:id="@+id/layout_nothingInList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@color/background"
android:padding="0dp"
android:visibility="invisible"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="50dp">
<ImageView
android:id="@+id/img_NoDreamsHint"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="false"
android:cropToPadding="true"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.39999998"
app:srcCompat="@drawable/sheep" />
<TextView
android:id="@+id/txt_NoDreamsHint"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="No dreams yet"
android:textColor="@color/splashScreenAction"
android:textSize="24sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/img_NoDreamsHint" />
</android.support.constraint.ConstraintLayout>
<RelativeLayout
android:id="@+id/layout_calendarPicker"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.prolificinteractive.materialcalendarview.MaterialCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mcv_allowClickDaysOutsideCurrentMonth="true"
app:mcv_arrowColor="@color/cardview_light_background"
app:mcv_dateTextAppearance="@style/CustomTextAppearanceDates"
app:mcv_firstDayOfWeek="monday"
app:mcv_headerTextAppearance="@style/CustomTextAppearanceMonth"
app:mcv_selectionColor="@color/colorAccentTrans"
app:mcv_tileSize="40dp"
app:mcv_tileWidth="50dp"
app:mcv_weekDayTextAppearance="@style/CustomTextAppearanceWeek"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="81dp" />
<ListView
android:id="@+id/listDreams"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/calendarView"
android:background="@color/background" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_AddDream"
style="@style/Widget.Design.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:clickable="true"
android:src="@drawable/add" />
</RelativeLayout>
</RelativeLayout>
希望这会有所帮助~
我自己修复了它:我的问题是在片段过渡之间,由于渲染和底层背景颜色,出现了白色背景。我需要添加到样式中的不是
<item name="android:background">color here</item>
相反,我不得不编辑
<item name="android:windowBackground">color here</item>
这解决了问题。