IT TIP

Android AppCompat 21 Elevation

itqueen 2020. 10. 20. 19:00
반응형

Android AppCompat 21 Elevation


View포장하지 않고 사전 롤리팝 장치에서 에 고도를 추가하는 방법 CardView있습니까?


ViewCompat.setElevation(View, int) 현재 shim을 생성하지 않습니다.

지금 고도를 시뮬레이션하는 유일한 방법은 v21 이전의 그림자를 적용하는 것입니다. 에서 스타일 / 레이아웃 / 드로어 블을 정의 values하고 values-v21. 버튼의 경우 스타일 재정의를 사용합니다. 레이아웃의 경우 일반적으로 참조 재정의 ( @null드로어 블을 제거 하는 사용) 사용 합니다.

향후 지원 라이브러리 업데이트로 shim이 추가되기를 바랍니다.

이 reddit 스레드 는 해당 업데이트를 추적합니다.

편집하다

새로운 지원 디자인 라이브러리는 실제로 플로팅 작업 버튼에 대한 shim을 생성합니다.


다음은 Toolbar롤리팝 이전 기기에서 아래에 그림자를 추가하는 방법의 예입니다 .

여기에 이미지 설명 입력

레이아웃은 다음과 같아야합니다.

<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>

그리고 그림자는 :

<?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>

나는 사용하여 동일한 효과를 얻습니다.

  android:background="@android:drawable/dialog_holo_light_frame"

내 테스트 결과 :

여기에 이미지 설명 입력

참조-https: //stackoverflow.com/a/25683148/3879847

업데이트 : 이 드로어 블의 색상을 변경하려면 @Irfan 답변을 시도하십시오.

https://stackoverflow.com/a/40815944/3879847


이제 스키마를 사용 xmlns:app="http://schemas.android.com/apk/res-auto"하고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">

참고 URL : https://stackoverflow.com/questions/26728570/android-appcompat-21-elevation

반응형