Android Widget Shadow which supports from API 16 - android

I want to have shadow in Android widget like button, edittext, searchview or anything. I have no idea about android elevation. I think it only supports from API 23. If there is any proper solution then please provide.
here is my demo widget. I need the shadow in border of my searchview.
<android.support.v7.widget.SearchView
android:id="#+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroud="#android:color/white" />

You can get the shadow effect by adding this to the widget:
android:background="#android:drawable/dialog_holo_light_frame"
Got the answer from here: https://stackoverflow.com/a/30931750/8466860.

Place your views inside CardView. Using CardView you can add elevation, rounded corners etc. It supports back till API 7.
to use CardView, add it via your app level gradle..
dependencies {
...
compile 'com.android.support:cardview-v7:25.3.1'
}

Related

How to implement shadow in Android?

My UX designer has provided me with an elegant design and exported it as an Xd file. For shadows of some elements, Xd gives me below information:
Shadow color: #101F400D
X: 0dp
Y: 3dp
Blur: 10dp
How can I create this layout in android with the above information?
Note: elevation is not what I want!
You can use cardView or Material design cardview to get the shadow effect
If you want to follow the guideline of material design you have to implement dependency
implementation 'com.google.android.material:material:1.2.0-alpha02'
You can use material cardview as shown below
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="4dp"
app:cardBackgroundColor="#color/colorWhite">
</androidx.constraintlayout.widget.ConstraintLayout>
You have to use a nine patch image to achieve this. Create a nine patch image using any tool like this - https://inloop.github.io/shadow4android/
Then, set this image as background to your view.

MotionLayout in AndroidX

I want to use MotionLayout but my app is in AndroidX, I have tried using the usual XML tags but they don't work. The Layout Editor just shows a gray box with the tag name. How do I use MotionLayout in AndroidX, or if that is not possible can you give me an alternative.
Thanks :)
It now happened with GridLayout too. Here are the screenshots:
This is just weird.
The code for GridLayout:
<androidx.gridlayout.widget.GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content>
</androidx.gridlayout.widget.GridLayout>
MotionLayout was added to ConstraintLayout 2.0 so make sure that you have
implementation 'androidx.constraintlayout:constraintlayout:$androidConstraintLayoutVersion'
within your app's build.gradle where $androidConstraintLayoutVersion is at least 2.0
hard to say without code,
but make sure that you xml tag is right:
<androidx.constraintlayout.motion.widget.MotionLayout ...>

FloatingActionButton (FAB) with Android Design support library not elevating

This is my FAB button:
<android.support.design.widget.FloatingActionButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="16dp"
android:src="#drawable/c"
app:elevation="6dp"
app:backgroundTint="#fa1d1d" />
I'm using the Design support lib: compile 'com.android.support:design:23.1.1' and testing on Android 6.0.1
The main problem is that regardless of the value I set for elevation, it looks the same every time. Here's the screenshot. First button has elevation set to 6, then 12, then 24
Feels like I'm missing something really simple.
It looks correct to me, I believe that you're misinterpreting the meaning of the elevation. Elevation only changes the shadow that is drawn under the view. From the docs:
The elevation of a view (...) determines the visual appearance of its shadow
(http://developer.android.com/training/material/shadows-clipping.html)
If you inspect closely, you'll see that the last button, the shadow is bigger and more "spread out".

Android: Set material design elevation for button using AppCompat V7

When following this Android tutorial using AppCompat V7 to get the new Tool Bar work, the android.support.v7.widget.Toolbar supports android:elevation on SDK's < Lollipop. This is because they use android.support.v7.widget.Toolbar and not Toolbar.
Is there equivalent for button? Something like android.support.v7.widget.Button? (This one not exist) Or any other workaround in the kind of overlaying the Button in some view supporting elevation? (I don't want implementation of creating custom shapes with gradients for look & feel of elevation).
Thanks,
You can use the Floating Action Button from support design library .
Use below code to the layout where you want this button.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_fab"
android:layout_gravity="bottom|end"
app:backgroundTint="#0091b4"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
android:layout_margin="10dp"
android:scaleType="centerCrop" />
Do add design dependency in your project
Add below in the dependency list of build.gradle file
compile 'com.android.support:design:23.0.1'
Unfortunately you will have to do what you do not want. Because there is no support button view yet. (As i know :) perhaps some omniscient person will correct my answer)

Android Unable to remove the color at the top and bottom

I have added a scrollView and if deploy on the android tablet,it has some problems. But it works fine on cellphone.
When users move to the top or bottom of the whole page,it will automatically show the blue shadow which indicates users reaching the bottom of the page.
I want to remove those indicator since it affects the UI.
Is there any way to remove or set in the XML?
I have tried different parameter to set on the scrollview but it doesn't work.
Please help.
fadingEdge is deprecated. Use this in your ScrollView: android:overScrollMode="never"
Add this extra line to your ScrollView definition:
android:overScrollMode="never"
or add this to your code:
findViewById(R.id.sobreScrollView).setOverScrollMode(ScrollView.OVER_SCROLL_NEV‌​ER);
Try this:
android:overScrollMode="never"
Add this to the scrollView
android:fadingEdge="none"
Pre API level 14:
android:fadingEdge="none"
API level 14+:
android:requiresFadingEdge="none"
See this:
https://developer.android.com/reference/android/R.attr.html#fadingEdge
This attribute is deprecated and will be ignored as of API level 14 (ICE_CREAM_SANDWICH). Using fading edges may introduce noticeable performance degradations and should be used only when required by the application's visual design. To request fading edges with API level 14 and above, use the android:requiresFadingEdge attribute instead.
setOverScrollMode(View.OVER_SCROLL_NEVER)
As mentioned by Romain Piel on this post: https://stackoverflow.com/a/7106752/956975, Pim Reijersen pointed out in the comments that android:fadingEdge is deprecated and will be ignored as of API level 14.
Remove the shadow on a ListView/GridView/ScrollView like so
in XML:
android:fadingEdgeLength="0dp"
in Java:
view.setFadingEdgeLength(0);

Categories

Resources