Tôi đang sử dụng thanh công cụ từ AppCompat V7 để thay thế thanh hành động trước đó và muốn có bóng của thanh công cụ như thanh hành động trước đó. nhưng thanh công cụ không có bóng theo mặc định và tôi đã thử các bản sửa lỗi được đề cập từ reddit. nhưng không may mắn.Material Design - Thanh công cụ AppCompat không hiển thị bóng
mã để thiết lập cái bóng:
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
Cách bố trí thanh công cụ:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="?attr/actionBarSize"
android:background="#F1F1F1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_margin="0dp"
foreground="?android:windowContentOverlay">
bố trí hoạt động:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:id="@+id/drawer_layout"
android:layout_height="match_parent">
<!-- activity view -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<FrameLayout android:id="@+id/fragment_container"
android:layout_below="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
<!-- navigation drawer -->
<RelativeLayout
android:id="@+id/left_drawer"
android:layout_gravity="start"
android:layout_width="match_parent"
android:background="#fff"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:divider="#eee"
android:background="#EEE"
android:id="@+id/drawer_header">
<ImageView
android:id="@+id/user_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:contentDescription="@string/user_icon"
android:src="@drawable/ic_action_person"
android:paddingTop="0dp"
android:paddingLeft="0dp"/>
<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/user_icon"
android:gravity="center"
android:layout_gravity="center_vertical"
android:layout_centerVertical="true"
android:textSize="14sp"
android:text="@string/not_logged_in"
android:paddingTop="0dp"
android:paddingBottom="0dp"/>
</RelativeLayout>
<ListView
android:id="@+id/drawer_list"
android:layout_below="@+id/drawer_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#eee"
android:background="#fff"
android:dividerHeight="0dp" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
Setting trong style.xml:
<style name="myAppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryColorDark</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:windowContentOverlay">@drawable/drawer_shadow</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/black</item>
</style>
bất cứ ai có thể giúp đỡ?
cảm ơn!
cập nhật 1: với đề xuất từ Willis, tôi nhận được bóng được hiển thị, nhưng nó không phải là bên dưới thanh công cụ, thay vào đó là bên trái của thanh công cụ.
Cập nhật 2: Tôi đã nhận thấy rằng nếu tôi không đặt cửa sổContentOverlay trong toolbar.xml và styles.xml, bóng sẽ thực sự ở trên cùng của thanh công cụ.
Hai là bóng tối hoàn toàn khác nhau. Cái dọc là của 'DrawerLayout'. Nó được cho là được hiển thị bên cạnh ngăn kéo mở rộng. Phần nằm ngang là một phần của 'windowContentOverlay' trên các API bên dưới' LOLLIPOP'. Khi bạn làm việc với tiện ích 'Thanh công cụ', thanh công cụ không phải là một phần của trang trí cửa sổ để bóng bắt đầu ở đầu cửa sổ trên thanh công cụ thay vì bên dưới thanh công cụ. Bạn cần thêm một 'View' trống bên dưới' Toolbar' pre-'LOLLIPOP' với nền của nó được đặt thành một bóng dọc có thể vẽ được (cao 8dp '# 20000000' đến' # 00000000'). Trên 'LOLLIPOP' bạn có thể đặt độ cao 8dp trên thanh công cụ. –
Hi Eugen, bạn đã cứu tôi trong ngày. Đây chính xác là những gì tôi cần, và nó hoạt động rất tốt dưới Lollipop trước. điều này sẽ là anwser chính xác. Bạn có thể đăng nó như là câu trả lời và tôi có thể chấp nhận điều này không. cảm ơn rất nhiều! –
Chỉ cần làm điều đó, vui vì tôi có thể phục vụ. –