Add a view shadow on android with appcelerator - android

i tried to put a shadow to my view on android, but i failed. I need to have a simply shadow like (and like iOS viewShadow property):

For Android you can use the Material Design cardviews, you can read about it here: http://www.appcelerator.com/blog/2015/11/titanium-5-1-0-sample-app/ which includes a sample app.
Documentation here: http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Android.CardView
var card = Ti.UI.Android.createCardView({
contentPadding: 20,
cardCornerRadius: 10,
cardUseCompatPadding: true
});
Most importantly, use the elevation property: http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Android.CardView-property-elevation
This requires TiSDK 5.1.2 or higher, which was released yesterday

Related

Justify align text in static layout?

How do I JUSTIFY align text in a static layout programmatically? Thanks for your time.
I only see the following options for staticLayout.setAlignment():
Layout.Alignment.ALIGN_CENTER
Layout.Alignment.ALIGN_NORMAL
Layout.Alignment.ALIGN_OPPOSITE
You can set it like textView.justificationMode = JUSTIFICATION_MODE_INTER_WORD. But it requires Android O (Api level 26).
source: https://stackoverflow.com/a/42991773/19115089
Another option would be to try a third party library like https://github.com/mathew-kurian/TextJustify-Android (but no longer maintained)

Shadow color android studio

I have a ui design.
I should to make some xml file with custom shadow color.
I used to carbon library but it not work very well
I need to create shadow like this
enter image description here
This should work for Android version 28 or higher.
In your xml layout, include this in your CardView.
android:outlineAmbientShadowColor="<yourColor>"
android:outlineSpotShadowColor="<yourColor>"
You can do the same in code by doing this:
mCardView.setOutlineAmbientShadowColor(ContextCompat.getColor(getContext(), R.color.color_blue));
mCardView.setOutlineSpotShadowColor(ContextCompat.getColor(getContext(), R.color.colour_blue));

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?

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

setCardElevation no effect pre Lollipop

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.

Categories

Resources