Có cách nào để thêm độ cao vào Viewthiết bị tiền kẹo mút mà không cần gói chúng trong một CardViewkhông?
CardView. Tôi muốn thêm nó vào bất kỳ Viewnếu có thể.
Có cách nào để thêm độ cao vào Viewthiết bị tiền kẹo mút mà không cần gói chúng trong một CardViewkhông?
CardView. Tôi muốn thêm nó vào bất kỳ Viewnếu có thể.
Câu trả lời:
ViewCompat.setElevation(View, int) hiện không tạo ra miếng chêm.
Cách duy nhất để mô phỏng độ cao ngay bây giờ là áp dụng bóng trước v21. Xác định phong cách / bố cục / có thể vẽ của bạn valuesvà ghi đè lên values-v21. Đối với các nút, tôi sử dụng ghi đè kiểu. Đối với bố cục, tôi thường ghi đè tham chiếu (sử dụng @nullđể loại bỏ một tệp có thể vẽ được).
Hy vọng rằng trong tương lai, bản cập nhật cho thư viện hỗ trợ sẽ thêm shims.
Chủ đề reddit này theo dõi cập nhật đã nói.
Thư viện thiết kế hỗ trợ mới thực sự tạo miếng chêm cho nút hành động nổi.
Đây là ví dụ về cách thêm bóng đổ bên dưới Toolbartrên các thiết bị tiền kẹo mút:

Bố cục phải là:
<RelativeLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:animateLayoutChanges="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
<View
android:id="@+id/toolbar_shadow"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_shadow"
android:layout_below="@id/toolbar"
android:background="@drawable/toolbar_dropshadow" />
</RelativeLayout>
Và bóng tối là:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#88444444"
android:startColor="@android:color/transparent" />
</shape>
Tôi đạt được hiệu quả tương tự bằng cách sử dụng,
android:background="@android:drawable/dialog_holo_light_frame"
Đầu ra đã thử nghiệm của tôi:

tham khảo - https://stackoverflow.com/a/25683148/3879847
Cập nhật: Nếu bạn muốn thay đổi màu sắc của câu trả lời có thể vẽ này, hãy thử @Irfan answer
Bây giờ bạn có thể sử dụng lược đồ xmlns:app="http://schemas.android.com/apk/res-auto"vàapp:elevation
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:elevation="5dp">