我的工具栏上没有阴影。大多数解决方案建议我将工具栏包装在AppBarLayout中,即使尝试这样做,也不会出现阴影。为什么即使有AppBarLayout时也没有阴影,该如何解决?
我不希望通过在工具栏下添加视图来获得阴影,是否还有其他稳定的方法来实现阴影。
这是我整个带有工具栏的xml布局:
<LinearLayout 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:orientation="vertical"
app:layout_scrollFlags="scroll|enterAlways|snap|exitUntilCollapsed">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="4dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/ab_gradient"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="@id/appbar">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:layout_scrollFlags="scroll|enterAlways|snap|exitUntilCollapsed">
<TextView
android:id="@+id/textViewProfilePhotoLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="@string/profile_photo_label"
android:textColor="@android:color/black"
android:textSize="16sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="6dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/textViewProfilePhotoLabel">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/circleImageViewProfilePhoto"
android:layout_width="140dp"
android:layout_height="140dp"
android:src="@color/colorBlack"
app:civ_border_color="#ffffff"
app:civ_border_width="3dp" />
<ImageView
android:id="@+id/imageViewEditProfilePhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_edit_black_24dp" />
</FrameLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutUsersFirstName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/frameLayout">
<android.support.design.widget.TextInputEditText
android:id="@+id/editTextUsersFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/users_first_name_label"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutUsersLastName"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/textInputLayoutUsersFirstName">
<android.support.design.widget.TextInputEditText
android:id="@+id/editTextUsersLastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/users_last_name_label"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutProfileHeadline"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/textInputLayoutUsersLastName">
<EditText
android:id="@+id/editTextProfileHeadline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/users_tagline_label"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutUsersEducation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/textInputLayoutProfileHeadline">
<EditText
android:id="@+id/editTextUsersEducation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/users_Education_label"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutUsersProfession"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/textInputLayoutUsersEducation">
<EditText
android:id="@+id/editTextUsersProfession"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/users_profession_label"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutUsersLocation"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/textInputLayoutUsersProfession">
<EditText
android:id="@+id/editTextUsersLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/users_location_label"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutUsersBio"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/textInputLayoutUsersLocation">
<EditText
android:id="@+id/editTextUsersBio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/users_about_me_label"
android:inputType="textAutoCorrect"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
</LinearLayout>
工具栏中使用的样式:
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
为什么我没有得到阴影,我该如何解决?
谢谢。
答案 0 :(得分:0)
像这样向工具栏添加elevation
和marginBottom
:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/ab_gradient"
android:elevation="4dp"
android:marginBottom="4dp"
app:popupTheme="@style/AppTheme.PopupOverlay" />