I'm trying to use "android: elevation ="
in my application but once I run it does not appear in the device with android 4.1.2
gradle
apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.example.alvaro.proyectocaronte" minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.3' }
layout.xml
maybe I'm not compiling correctly Lollipop for pre-lollipop devices, Any suggestions?
If you need to see other parts of the code, I'll edit the question
Thanks
Elevation requires the device to run Lollipop. See this answer on how to simulate elevation https://stackoverflow.com/a/26747592/680249
You can also use a CardView from the support library to implement surfaces.
To do so add a dependency to your build.gradle:
compile 'com.android.support:cardview-v7:23.1.1'
And then simply use it in your layouts:
Here you have a quite more options to customise it comparing to using @android:drawable/dialog_holo_light_frame
as a background
EDIT:
Also notice, that this approach allows you to simply implement
Material Design on Pre-Lolipop devices.
You can change the elevation,
round the corners etc.
To do so you have to:
app:cardElevation="8dp" app:cardCornerRadius="8dp" app:contentPadding="5dp">
And not forget to add xmlns:app="http://schemas.android.com/apk/res-auto"
to the root layout.
Also you can easily change the elevation in your code:
CardView card = (CardView) findViewById(R.id.yourPreetyCoolCardView); card.setCardElevation(getResources() .getDimension(R.dimen.card_picked_up_elevation));
Use 8dp
for picked up and 2dp
for resting (usual) state and you will be awesome.