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));
Related
Want this kind of shadow effect with android card view except for white background with cardview property, neither use with the canvas draw mechanism nor 9 patch image mechanism
want to use only drawable shape or cardview properties. TIA
EDIT: There is this github project you can use to get custom shadow for CardView. Just implement it in your project and use this instead of androidx components. Link: https://github.com/nvl2val/CardView/tree/master
2nd EDIT: Also another workaround for this issue. Read this thread: Android change Material elevation shadow color
I don't really get your question but CardView itself has a lot of properties you can play with. Check this documentation for more: https://developer.android.com/reference/androidx/cardview/widget/CardView
Using elevation will give you shadow by default so if you don't want a shadow on objects with a white background you need to set the elevation to 0. Here you can play with
android:elevation = "10dp"
app:cardElevation = "10dp"
and see which one does the job better for you. Also, try adding some padding to your parent layout so that CardView has some space around. All this and maybe more you can find in this answer: https://stackoverflow.com/a/46374054/14759470
I need to draw categories path like in the picture bellow, problem is item shape
what would be a best practice to achieve it?
I can think about few options like:
Extending TextView and changing it shape
Adding vector drawable background
Adding xml drawable background
Any ideas?
Following are my understanding:
Extending TextView and changing it shape
This will load TextView at runtime and so will not be memory-efficient.
Adding vector drawable background
This is a good practice. But the native Vector drawable support is from API level 21. To support lower api devices you will need to add vectorDrawables.useSupportLibrary = true and modify build.gradle file as:
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
Android Studio 1.4+ will generate pngs at build time.
Adding xml drawable background
This will support all the versions and kind of the easiest solution.
My suggestion will be to use Vectordrawables. This will give the
best support with different Android versions.
I think i mentioned the name of the shape wrong.
I want to make shape like the following image with shadows in Android,
Sample model
So how to make this type of layout in Android .
thanx for the help!!
You should try this one:
https://github.com/Hitomis/CrazyShadow
By drawable you can generate the shape, and by using this library you will be able to add shadow.
Or:
You can use the library itself.
I was using SVG's in my Android application as src of my ImageView, using appSrc attribute in order to give compatibility backwards (SDK<21).
But now I have tried to use them in my TextView Compound Drawables (drawableXXX attributes) and I get multiple errors when I use a device with KitKat (The same errores that I had when I used android:src instead of app:srcCompat).
Caused by: android.view.InflateException: Binary XML file line #261: Error inflating class
Is there anyone who know a way to use them in Compound Drawables?
as of now you cannot add a VectorDrawable from xml attributes, that functionality is only limited to app:srcCompat more on this in the android developers blog post
However you may do it programmatically using VectorDrawableCompat.create(Resources, int, Theme) and then add it as a compound drawable to the TextView using TextView#setCompoundDrawables
see :
developer.android.com/reference/android/support/graphics/drawable/VectorDrawableCompat.html
developer.android.com/reference/android/widget/TextView.html
I had the same issue and i found only two options:
1) set your drawable programmatically or create a custom view
2) remove "vectorDrawables.useSupportLibrary = true" from your build.gradle
This will cause Android Studio to generate PNGs at compile time for apps with a minSdkVersion less than API 21 while using your vectors on API 21+ devices, allowing you to keep the same code at the cost of additional APK size.
As is described in this article, you can create a little hack for this issue. Just create layer-list drawable file(ic_working_image.xml) like this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_your_image_name"/>
</layer-list>
And then just use the new drawable on TextView as before with drawableXXX attributes.
An edittext looks different in a 2.2 emulator than it does in a 4.2 version. I want to make my edittext look like it does in the holo light version on a 4.2 emulator.
I have no idea how to do this, do I need to write my own custom style? Thanks in advance
Are you sure that you want to do this? Users of 2.2 devices may not recognize an EditText with holo styling. Remember that there are very few people who have both a 2.x and a 4.x device. Usually, you want a look and feel that will be natural for the user.
That being said, if you are sure that you want to do this, you are welcome to try to get HoloEverywhere working.
I found this web:
Android Holo Colors
check out these links :
1. How to create ICS holo style edit text for older versions?
2. How to create EditText with rounded corners?
3. Styling EditText view with shape drawable to look similar to new holographic theme for Android < 3.0
Is it possible to make an EditText in android 2.x that looks like an EditText from Android 4?
Check the above answer to the Question,
Or You can use the following method (referred from the above question):
add the below code to res\values\styles.xml
<style name="HoloEditText">
<item name="android:background">#drawable/edit_text_holo_light</item>
</style>
After that from YOURPATH\android-sdk\platforms\android-16\data\res\ just copy the edit_text_holo_light.xml and all referenced drawables to the corresponding directories in your project.
And then simply apply the style to your EditText:
<EditText
android:id="#+id/editText"
style="#style/HoloEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>