setCardElevation no effect pre Lollipop - android

setCardElevation has no effect for me on a 4.4 device - works on 5.0 - but from what I read in the documentation it should work on pre-L - do you have to do something different than:
cardView.setCardElevation(8dp)

Try using this:
cardview.setMaxCardElevation(8);
From the CardView docs:
If you want to change elevation dynamically, you should call setMaxCardElevation(float) when CardView is initialized.

Related

includeFontPadding doesn't works in API 21

I'm using the includeFontPadding = false to remove the font spacing in my TextView's and in Android 28(Right) works fine but in Android 21(Left) still with the font padding in the top.
I was checking in the android developers documentation and the setIncludeFontPadding was introduced in API 1.
Do you have an idea what's happening?

AppCompatButton on Android 5: app:backgroundTint works but supportBackgroundTintList does NOT :(

I need to reuse XML layout and change button color programmatically.
In Android 5 applying app:backgroundTint in XML changes button color but I need to do it programmatically and I do it in Recyclerview:
holder.button.supportBackgroundTintList = ContextCompat.getColorStateList(context, backgroundColorRes)
This has no effect.
The setSupportBackgroundTintList() method is annotated with #RestrictTo({Scope.LIBRARY_GROUP}), which means you are not supposed to call it directly. Instead, you should use ViewCompat.setBackgroundTintList().
Try changing your code to this instead:
val colorStateList = ContextCompat.getColorStateList(context, backgroundColorRes)
ViewCompat.setBackgroundTintList(holder.button, colorStateList)
If you look at the source code for ViewCompat.setBackgroundTintList(), you'll see that it does different things for API 21+ (Android 5 and higher) than earlier versions. Chances are good that the "support" background tint is only applied on earlier versions of Android, and ViewCompat will make it so that you don't have to think about that.

How to remove the shadow on top of DrawerLayout in android 5.0+

I'm using API 19, and I have the following shadow showing up over my DrawerLayout in newer versions of android (API 22 for example).
Screenshot
I want it gone, and I can't figure out how to achieve this.
What I've tried so far:
Setting elevation on literally every element to 0dp in the XML,
setting the elevation programatically for the DrawerLayout and Toolbar using getSupportToolbar(),
setting the shadow to an empty Drawable,
adding various other settings in style XML with no result.
For my case just removed the line from the parent layout and the problem have solved!
android:fitsSystemWindows="true"
By the way, I have also tried all the solution I have known! But there is no solution until I removed "android:fitsSystemWindows" attribute from the parent layout. Hope this will help who will suffer the same problem. Thanks.

Material Design for pre-lollipop

I'm working with material design and I faced the problem I can't solve. It's about the shadows/elevation.
Here we can read about the shadows and elevations in Material Design
https://developer.android.com/training/material/shadows-clipping.html#Shadows
But we can use these features only in lollipop and higher.
And what about the pre-lollipop devices? If I want to create the app which could be used at pre-lollipop devices then I can't use, for example
android:elevation="2dp"
Am I right?
If so then all I can do - it's using the design drawables which already include their shadows.
And here's another issue that I can't get.
For example, the designer gives me psd with some design. Imagine it looks like this
As you can see, top margin of the panel is 448px. We can easily get this margin value using the Photoshop.
But when I extracted this panel with its shadow then I discover that shadow by itself takes 10 px at the top of the panel
That 448px top margin doesn't count the shadow.
Obviously I can't just put panel.png on my some_layout.xml and set the margin top as 448px(298.67dp) because this drawable includes the shadow. It seems I should consider the shadow length and I should deduct this length from the top margin (448-10=438px=292dp).
Is this reasoning correct? I just can't believe it. This way seems to be too complicated. Maybe more effective practice exists?
According to shadow in Pre Lollipop devices
For Android 5.0 and above : AppBarLayout automatically provides/gives
shadow in the layout. You can also increase the elevation of the
AppBarLayout by android:elevation="4dp"
For Pre-Lollipop : You can use the following link:
http://blog.grafixartist.com/add-a-toolbar-elevation-on-pre-lollipop/
Note: Toolbar also supports elevation to it, using
android:elevation="4dp"
Read more: Add elevation/shadow on toolbar for pre-lollipop devices
According to elevation in Pre Lollipop devices
You can't mimic the elevation on pre-Lollipop with a official method.
You can use some drawables to make the shadow in your component.
Google uses this way in CardView for example.
The ViewCompat.setElevation(View, int) currently creates the shadow
only on API21+. If you check the code behind, this method calls:
API 21+:
#Override
public void setElevation(View view, float elevation) {
ViewCompatLollipop.setElevation(view, elevation);
}
API < 21
#Override
public void setElevation(View view, float elevation) {
}
Read more: How to implement the Material-design Elevation for Pre-lollipop
EDIT: As #geek90 suggest visit also this repo: http://github.com/navasmdc/MaterialDesignLibrary
It frustrated me too. I didn't like making shadows with gradients. I dove into the documentation, found how is the Lollipop's implementation done and coded that from scratch for older devices.
My implementation is called Carbon. It's a Material Design implementation with support for dynamic, automatic shadows. No need to add any kind of margin or gradient - just specify elevation for a view and get shadows on all SDKs.
https://github.com/ZieIony/Carbon
Read more about the method here: How to implement the Material-design Elevation for Pre-lollipop

Elevation + transparency bug on Android Lollipop

Using a background color for a view with some alpha (e.g. #99fe0038) and some elevation on API 21 reveals two circles: one for the view itself and another inside:
Elevation and background color are set via code:
view.setElevation(getResources().getDimensionPixelSize(R.dimen.fab_elevation_lollipop));
view.setBackgroundColor(Color.parseColor("#99fe0038"));
Without setting elevation or with using an opaque color everything looks like expected.
Is it an Android bug or have I missed something here?
Removing shadow effect worked for me.
FAB.setShadow(false);
FAB.setBackgroundColor(getResources().getColor(R.color.fab_transparent));

Categories

Resources