Transparent white button looks bad in Android Material Design - android

Consider these 2 screenshots. I defined the elements on the left, top, and bottom-right:
The left/top screenshot has all my elements using a solid white (#FFFFFF) while the bottom/right one adds a bit of transparency (#D0FFFFFF). My issue is that my elements look hideous with transparency. For example the FAB (bottom-right) contains a smaller opaque circle for no reason.
All my elements have elevation 6 (as that is the FAB default elevation). Anything greater-than elevation 2 has this issue clearly visible, and anything below 2 does not cast enough shadow for me to look acceptable.
The Maps-defined element (top-right) seems completely unaffected by this however! What is it doing differently? It's clearly using transparency like me and also casting a shadow corresponding to elevation 2 or more.
Code used is basically this:
fab = FloatingActionButton(this.context!!)
fab.backgroundTintList = ColorStateList.valueOf(Color.parseColor("#d0ffffff"))
fab.compatElevation = 6F

For example the FAB (bottom-right) contains a smaller opaque circle
for no reason.
later on... fab.compatElevation = 6F
 
The circle you are seeing it's FAB's shadow, which is generated by the elevation.
If you want to remove the shadow but keep the elevation, do:
fab.outlineProvider = null
If you want to keep both elevation and shadow, you have to make a custom outlineProvider (probably a banana shaped one).

Related

Shapeable image view - corner color - android

In the second fragment I have used shapeable image view with shape appearance overlay to rounded. while applying material container transform, black corner are visible in shapeable image view. Help me how to remove the black corners.
I faced the same issue recently. I was setting background color to RED for example, but on lower android versions, corners got black just like in your case.
a workaround I came up with was to set background of ImageView using following lines of code:
imageView.background = ShapeDrawable(RectShape()).also {
it.paint.color = myColor
}

Android How to create a Glowing Border or Four side shadow Rectangle Shape Background

I want to fill the background of multiple size (custom width or height) constraint layouts with this design:
Noticed that the outline border is glowing with fading gold color.
I have tried with the following:
Attempt (A) is using of ImageView tag, but not scalable to custom width and height.
Attempt (B) is xml created. But the border color is not fading, isn't the desired result.
Attempt (C) is using 9 patch file. The border radius and corner radius does not seems correct at all. (Would also like to know reason of this)
This is my 9patch file:
May I know if this is even possible to achieve?
Anyone please help.

Fill shape with text with two different color

I tried to achieve this but I am only able to achieve to fill object (shape).
My requirement is to change text color along with shape filling.
Shape can be filled with percentage like till
10% to 50% = Green
51% to 80% = Yellow
81% to 100% = Red
When Yellow color fills background of ":" in shape, it will change color to "White" which is previously "Yellow". Size of this shape is also dynamic.
What I tried and achieved?
I am able to fill shape with percentage but failed to change color when it reaches to edge of text.
I wrote a custom view. You get this double color effect using Path APIs. But for Android 1+ compatibility, you should use Region API and above Kitkat (19+) you can use just Path API.
Let's go through the concept of how to achieve this effect step by step:
There are three shapes we need to draw - Outline Rounded Stroke + Orange Progress Bar + the text itself
We draw the stroke as it is
But for the Progress bar, we need to remove the text that intersects with it and basically make the text intersection transparent. (DIFFERENCE)
Also for the Progress Bar, we have to show only the part of the rectangle that intersects with the outer rounded stroke path. (INTERSECTION)
And similarly, for the text, on the left side we basically chop off the parts that intersects with the progress bar. And we only show the right side of the text that is orange in color. (DIFFERENCE again)
If you are using API 19+, this is how the critical code snippet looks like:
croppedProgressPath.op(progressPath, textPath, Path.Op.DIFFERENCE);
croppedProgressPath.op(progressStrokePath, Path.Op.INTERSECT);
————————————
croppedTextPath.op(textPath, progressPath, Path.Op.DIFFERENCE);
Lines here and here.
I’ve written a Proof of Concept for this project called Diffre on Github. If you wanna test it out first, all the code is in this repo.

How to put time delay in COCOS2D Android

Similar to Android unlock pattern where in, initially all the circular cells will be in grey color. During when we draw some pattern, those cells touched will become green colored and if that pattern is not a correct one, then the cells touched will become red colored and after some 3 seconds, they become grey colored. I am doing similar thing using COCOS2D. I am getting difficulty in introducing that 3 seconds delay before making the cells back to grey colored. Any suggestions...Thanks.
You can use CCSequence in that first put CCDelayTime and in second put CCCallFuncN(which contain logic of again color your circle to grey)
Below i am providing you iOs code logic
id action1 = [DelayTime ...];
id action2 = [CallFunc ...];
id seq = [Sequence actions:action1, action2, nil];
[someNode runAction:seq];

Influence of nine patch image non stretchable size on padding of component using it as background

I got a widget and when I use a color as a background, all the components inside have a 0 padding when I use android:layout_alignParentTop="true" (same for other sides).
But when I use a 9 patch image as the background of the parent, it seems to have a padding that is equal to the non stretchable size of the 9 patch image when I align them on their parent.
Is this normal ?
There are two main parts to a nine-patch: the stretchable areas and the content-defined areas. The top and left pixel border define the stretchable area, as I'm sure you're aware. The bottom and right, however, define the CONTENT area. If you want the padding to go away, you need to make the bottom and right bar extend all the way to the edge of the artwork (not all the way to the corner pixels, though!). Basically, the right and bottom pixel border define your padding.

Categories

Resources