Hi I'm trying to apply a shadow to a linearlayout with the following code
if (<some condition>)
layout.setElevation(4);
but this call requires API level 21 to work. How can I apply a shadow to layouts for devices with version < 5.0? Is it possible?
I know this is part of Material Design which is why I just want to know if there is a way to achieve something similar in previous versions, thanks :)
Use ViewCompat.setElevation(view, elevation);
Related
I am targeting api 17, and I would like to have shadows on devices that support material design. Is there something like "If shadows supported, use shadows"?
Adding android:elevation did solve it.
I thought that this attribute will crash on pre-lollipop devices, as it is not shown in layout editor when minSDK is set to less than 21.
I'm trying to add simple button on my layout, my min api is 14, The problem is when run the app on android < 5.0 the button doesn't have any animation , How can I fix that?
I think the animation you are talking about is Ripple Effect. That is a feature of material design. And remember the official material design theme is supported for android >= 5.0.
I guess that you are using default theme. So, when you run your app on android 5.0 or above it will using material theme (with ripple effect for button). However, when you run android < 5.0, the theme now is not material theme and button doesn't have ripple effect.
For solve your problem, you need using third party libraries to apply material design to your app. Here is list of awesome ui library and you can find some libraries that help you applying material design.
The list of awesome ui library: https://github.com/wasabeef/awesome-android-ui
I'm using com.android.support:appcompat-v7:22.2.0 to make Lolipop material design on pre-Lolipop devices. The problem is that widgets (example EditText) are displaying different views with different parameters on different API.
Question is how to make it all looks the same on all API 15 and above?
Example here (different bottom line, margin between text and line etc.):
I think that I found solution.
AppCompat generates proper look during inflating layout.
If API < 20 it generates look like newest API (ex. 22).
If API >= 21 it generates look depending on API.
Don't look at preview in XML (my image is from previews). Open emulator and check by yourself how it will looks on device.
Hope it helps someone in future.
I try what simon tell to do for change direction but it's doesn't working.
It's seems that for hundredth of a second it's work but when Action bar add the action buttons it's put the buttons at left instead at right.
What can be the problem? it's seems that somewhere in nmy code had line that tell freamwork to do otherwise?
The RTL value (true or false) is included in the flags in getApplicationInfo.flags.
As a long shot - is it possible that you are somehow changing the value?
The ability to set RTL was added in Android 4.2 if you are supporting this OS level or higher, this will be easier for you to accomplish.
Proof it is 4.2+: https://groups.google.com/forum/#!topic/actionbarsherlock/-npidM2Eo0w
Google post outlining how to change to RTL: https://plus.google.com/+AndroidDevelopers/posts/HuHNSb8V7s8
Otherwise, I would reference the SO question already pointed to in another comment if you are supporting an OS level older than 4.2: How to handle RTL languages on pre 4.2 versions of Android?
I want to know if someone knows a library that contains a back ported implementation for ListPopupMenu that works on pre android 11
I don't but you could use PopupWindow whcich is available since API 1. You can create a list as your contentView. You can use showAsDropDown which could give you the same type of effect
This might be worth checking out. I like to use it for backwards compatibility sometimes for the effect it gives
PopupWindow
showAsDropDown