How can the top padding be removed from Android JetPack Compose ModalBottomSheetLayout? - android

I have tried for a few hours without success to remove the top padding from the Compose ModalBottomSheetLayout.
I tried debugging through the internal material classes to trace where the padding is being set and can't for the life of me work it out!
I want to add a background image which completely fills the ModalBottomSheetLayout right up to and including the rounded corners but clipped by them. Even if I remove the rounded corners (see pic) the issue remains with the extra padding above the sheetContent.
I have added an image with some background colors showing the issue. The blue bar is the top (extra unknown padding) of the bottom sheet opened at HalfExpanded state.
Another example with the rounded corners:

Related

How to draw an oval with Inner shadow like Figma's inner shadow for Android?

I need to make an oval button with 2 inner shadows: white on the top and black on the bottom.
I have a design from Figma (check the attachment).
I have already tried many-many combinations of shapes/gradients/angels/paddings with layer-list but nothing seems to be similar to the expected result. How can I draw it? Thanks in advance.
Here is the bottom black shadow settings:
Here is the top white shadow settings:
Here is the expected result:
Thanks in advance!

How can we fix the elevation shadows on transparent/translucent Views without changing the existing setup?

A somewhat well-known issue in Android, since Lollipop and the introduction of Material Design, is that elevated Views with see-through backgrounds reveal ugly artifacts from their shadow draws behind them.
Those visual glitches are all caused by the shadows being adjusted for increasing elevation by kind of "zooming out" on the gradients, which causes their inner borders to shrink inward within the View's bounds, normally unseen in ones with opaque backgrounds. No clipping is done there, and every relevant check I've come across in the source turns the shadow off completely when that artifact would be seen, so that clipping is seemingly omitted intentionally, likely for efficiency.
As you might expect, many questions have been posted about it here over the years, but turning it off or somehow avoiding it altogether seem to be about the only generally effective solutions other users have found, as well:
How to set semi transparent background color for Android CardView?
CardView background alpha colour not working correctly
Cardview - rounded corners with transparent background
Elevation + transparency bug on Android Lollipop
How to create a shape with a transparent background and a shadow, but the shadow should not be visible behind the shape outline?
CardView with transparent background issue on > API 21
Weird view behavior when an elevation and a transparent background color are used on API 21
Remove background colour from FloatingActionButton
Android Floating Action Button Semi Transparent Background Color
How to set border and background color of Floating Action Button with transparency through xml?
How to center image in FloatingActionButton behind transparent background?
How to remove those dark circular background from floating action button?
Android transparency and Shadows
a shadow appear below material button after setting background color tint in android
Multiple layers of shadows in android recyclerview elevation
How to adjust shadow in translucent navbar?
Transparent white button looks bad in Android Material Design
Various bespoke workarounds are available for a few common setups, some users ignore it or don't realize what it is, and some have even integrated the effect into their designs, but I still have not found a single example where it's been truly fixed. I haven't gone digging into the native graphics code yet, but I also can't find any instance in the SDK source where anything is done about it other than disabling the shadow when that might be visible, and if we're not able to do it at the app level it doesn't really matter what the low-level graphics stuff can do.
There doesn't seem to be much out there about the general problem, but recently I'd shared some information about it on this old question concerning CardView, including a couple of basic techniques for creating clipped shadow replicas as replacements. However, the examples in that answer are quite specific, and adjusting them for multiple different Views would be tedious and error-prone, and would likely require some not-insignificant modifications to an existing setup in order to add them.
Is there any way to apply those workarounds generally, and with minimal changes?

Preventing Pixelation of Images, indenting listViews and adding Rounded corners

I have a few issues and questions regarding some UI development on Android. Firstly look at this image:
Firstly at image A) This is a image that I insert and repeat horizontally to give the zig-zag shape at the top of the screen regardless of screensize and above that a textField with no content and a background color - But as I'm sure you can is that the two colors don't match up quite as perfectly as it should even though they both have the same hex color value (#BF0426). And secondly, you can also see some serious pixelation on that zig-zag image. How do I fix these 2 problems?
And then at image B) Here I have a simple listView. What I would like to do, is firstly indent it a bit on both sides, and round the corners of the top and bottom item. So basically I want it to look like the blue border drawn on the screenshot. (Your typical iOS listView). How do I go about doing this?
Thanks in advance for any tips!
For the image. Just out of curiosity, why wouldnt you simply extend your image to include the top pixels as well? In other words, build your repeating image such that it incorporates the pixels that you are trying to create using the empty textview. This will at least take care of the color missmatch, as the color will all be generated from the same place. In terms of the pixelation. Are you truly repeating the image, or are you spreading the image. A spreading will definitely cause what you are seeing.
For your tableview:
For the left and right indent, you can simply use the margin or padding attributes of tableview item. There are generic padding and/or margin attributes (which will pad all of the top, bottom, left and right), or there are separate padding and/or margin attributes for each top, bottom, left, and right. Here is a great link on padding versus margin that you may want to read.
Difference between a View's Padding and Margin
Example attribute (as called in an XML file) for bottom margin
android:layout_marginBottom
setMargins(left, top, right, bottom) // for setting margins programmatically
Example attribute (as called in an XML file) for top padding
android:paddingTop
setPadding(left, top, right, bottom) // for setting padding programmatically
For the custom top and bottom, you should be able to use the following tutorial
http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
From here, you should be able to detect the item as the first and last item and set the background property (image) to a background image that has a rounded top or rounded bottom. This is how I do it on the iPhone. I have also implemented things that LOOK like tableviews but are simply vertical layouts with my own custom views that I have made to look like what you are wanting.
One thing to consider is the file format you use is going to mutate the image as you save it (lossy compression), so a .jpg with a certain color may look different than a .bmp with the same color. Make sure you author using the same application and/or export settings when trying to match up images.
Also, if you created your image with a DPI that is not compatible with the android display it can cause serious pixelation in detail areas, especially with gradients and drop shadows.

Nine-Patch Image Slicing, Padding Issue

So I've patched an image however it has padding on the left and right which I DO NOT want, however when I patch the image without padding the corners on the image get distorted when it's drawn in a layout.
Below is a screenshot of how I am doing it, how would you overcome this issue?
Maybe just try to specify the padding the way it's meant to be specified, i.e. by drawing the bottom (and right if you want) border in 9-patch tool. Like this:
This way the padding should be right (side to side) and corners not distorted.
The left and top lines define the stretchable area. When you include your corners in the stretchable area, the image gets distorted. In this case, one black pixel touching the center of the image on the left and the same on the top would suffice.
To identify the rectangle for the view contents, and thus the padding, you can use right and bottom lines.

Honeycomb actionbar and margins

I'm attempting to use a different "homeAsUpIndicator" graphic on the action bar, and I'm running into some margin issues with the edge of the screen and the graphic.
Using the "android:homeAsUpIndicator" attribute with a value of #drawable/my_graphic in the styles.xml for the project, I've managed to change the indicator to a custom graphic. That graphic has been designed with a 0dp left margin in mind - as in the left edge of the graphic should go all the way to the left edge of the screen. Instead, I'm getting a 6 pixel margin on both the top and the left side the image.
I've tried setting the margins and padding in my styles.xml, but either that doesn't work or I've applied it to the wrong resource. Also, I tried setting the actionbar background to a 9-patch graphic and let the standard indicator graphic (the "<" in Honeycomb 3.1) float on top of it...that didn't work either, as it just pushed the indicator graphic to the right of the fixed pixels of the background. It only overlayed the pixels that were identified as the stretch pixels in the 9-patch.
Is there a way to remove the 6-pixel padding/margin from the actionbar so the indicator graphic is flush with the left side of the screen? Any examples or leads would be greatly appreciated!
Thank you
Have you provided drawables for different screen sizes / resolutions / densities?
Though they should resize automatically.
See here for icon design of action bar :
http://developer.android.com/guide/practices/ui_guidelines/icon_design_action_bar.html
Also you can check the standard icons being used in your sdk folder and adapt yours to those:
the path is:
ANDROID_SDK/platforms/android-XX/data/res/drawable-XXX
https://stackoverflow.com/questions/8179653/where-can-i-find-standarts-icons-for-actionbar
Otherwise check also here:
How to remove the margin between the app icon and the edge of the screen on the ActionBar?
Also you could use a custom action bar:
Custom title bar without padding (Android)

Categories

Resources