Android XML: android:elevation vs. app:elevation

前端 未结 3 1538
生来不讨喜
生来不讨喜 2020-12-15 16:19

When do I use android:elevation and when app:elevation?

What\'s the difference between those two?

相关标签:
3条回答
  • 2020-12-15 16:52

    There is one more thing:

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/spacing"
        android:src="@drawable/svg_my_location"
        app:elevation="4dp" />
    
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/bottomSheet"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@drawable/shape_rect_round_white"
        app:elevation="8dp"
        app:behavior_hideable="true"
        app:behavior_peekHeight="100dp"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"/>
    

    With using app FloatingActionButton is visible

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/spacing"
        android:src="@drawable/svg_my_location"
        android:background="4dp" />
    
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/bottomSheet"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@drawable/shape_rect_round_white"
        android:background="8dp"
        app:behavior_hideable="true"
        app:behavior_peekHeight="100dp"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"/>
    

    When you're using android FloatingActionButton is invisible, because it overlapped by bottom sheet

    0 讨论(0)
  • 2020-12-15 17:14

    app:elevation - if you are using support library (for supporting old versions of Android) android:elevation - if you are not using support library

    0 讨论(0)
  • 2020-12-15 17:16

    Hope I can help, Let's talk with an example:

    <android.support.design.widget.FloatingActionButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        ...
        android:elevation="@dimen/elevation_medium"
        /> 
    

    The android:elevationattribute will work from the API level 21 and upper.

    <android.support.design.widget.FloatingActionButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        ...
        app:elevation="@dimen/elevation_medium"
        /> 
    

    In this case the app:elevation attribute belongs to the FloatingActionButton styleable, inside de Android Design Support Library which will work from version 4 of the framework, instead version 21, the case of android:elevation.

    0 讨论(0)
提交回复
热议问题