I am using the new Bottom App Bar from the Material Design Components. I am trying to give shadow at the top of the Bottom App Bar like the one in Google Tasks app as shown below.
I have tried using both android:elevation and app:elevation attribute. Please help.
I ended up using this solution.
Step 1
Create a shape_drawable.xml file in the drawable folder as shown below:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#1F000000"
android:endColor="#android:color/transparent"
android:angle="90" />
</shape>
Step 2
Create a View, set the shape_drawable.xml as its background and then place the view just above the BottomAppBar.
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="#id/bottom_bar"
android:background="#drawable/shape_drawable"/>
Elevation has been fixed in the Android material components 1.1.0 (alpha) release according to this commit.
Edit
for those wondering, this is how you add the new dependency:
dependencies {
// ...
implementation 'com.google.android.material:material:1.1.0-alpha02'
// ...
}
More information about getting started can be found here and info about releases can be found here.
Cheers!
Related
I am trying to set gradient color in Button (in android studio whose version is Arctic Fox).
gradientbuttonmainactivity.xml
I made this file in Drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#93501C"
android:endColor="#A67E7E"
android:type="linear"
android:angle="360"/>
<corners
android:radius="25dp"/>
</shape>
activity_main.xml
<Button
android:id="#+id/btnR"
android:layout_width="275dp"
android:layout_height="55dp"
android:layout_marginStart="55dp"
android:layout_marginTop="25dp"
android:background="#drawable/gradientbuttonmainactivity"
android:text="#string/register" />
but Button color is as it was, corners values applied but gradient values did'nt.
I searched it on google but didn't found any working solution.
In one stackoverflow answer, a writer said to change the colorPrimary (in theme.xml) with #null. I done this , and gradient color applied, but on Run, the app failed to open in the smartphone, however, it launched successfully.
So, the question is clear, How do I make the button with gradient color ? Thank You.
As an alternative, try using
androidx.appcompat.widget.AppCompatButton
instead of
Button
it might be a recent change with Button and Android's material design, I've noticed on older projects what you have implemented works with Button but on a more recent project, that background is not working
I want to applying drawable to my android button.
But, background drawable is not working.
This is my drawable code.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFEF1D1D" />
</shape>
</item>
</layer-list>
and This is my layout code
<Button
android:id="#+id/booking"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6.5"
android:text="bokking"
android:textStyle="bold"
android:textColor="#color/white"
android:background="#drawable/booking_btn"
android:layout_marginRight="10dp"/>
Drawable is not applied to Button, but drawable is applied to AppCompatButton. I wonder why too.
When I applied this code, Only backgroundTint applies to buttons.
I spent a week on this issue, but I couldn't solve it.
plz help me
You can't apply the background on the material button.
If you are using Theme.MaterialComponents.*, then the normal button also used as the material button forcefully.
You have two options.
change it to any AppCompat theme.
Still If you need a material theme for some components, then use any material theme with a bridge. like Theme.MaterialComponents.*.Bridge
So, If you will go with option 2, you can use material button as per your need.
use com.google.android.material.button.MaterialButton for material button else use your normal button.
Looks like there is a problem with the Theme since Android Studio 4.1, try changing the base Theme from Theme.MaterialComponents.DayNight.DarkActionBar to Theme.AppCompat.DayNight.DarkActionBar, it works for me.
There is only one chance for that.I think you are using material theme.That's why the background property is not applying for button.If you want use that,change the theme to appcompat varaint.
You didn't use the selector in your XML. Use Selector instead of Layer-List
So, I am developing an android application, and across all the layouts that I have created so far, I have buttons, not AppCompatButton or Material Button just plain simple button which has the following attributes set:
<Button
android:id="#+id/logout"
android:layout_margin="8dp"
android:text="#string/log_out_button"
android:textColor="#000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_buttons"
app:layout_constraintBottom_toBottomOf="parent"/>
rounded_buttons.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFF"/>
<corners
android:radius="8dp"/>
</shape>
This throws a fidelity warning:
Paint.letterspacing() not supported.
The weird part is this xml when referenced in layouts created earlier works as intended.
I appreciate any help you could provide.
If it helps this started after I installed a third party plugin to import material icons:
Material Icon Generator
I have since disabled this plugin, invalidated caches and restarted the ide, somewhere on SO, it suggested to change the theme, tried that to no avail, so changed it back to the one I was using.
This is pretty embarrassing, All I had to do was change the theme in the preview from
Material Components to AppTheme.
Pretty stupid to not have figured this out earlier.
Also the Material Icon generator is pretty great and did not cause this issue.
I'm implementing Bottom Navigation Bar in Android app using Google's support design library v25.1.0. Is there any way to add drop shadow effect, same as current Android native Google Photos app?
You can draw your own shadow just above the bottom bar using simple View and its background:
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="#id/bottom_bar"
android:background="#drawable/shadow"/>
drawable/shadow.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#1F000000"
android:endColor="#android:color/transparent"
android:angle="90" />
</shape>
Also, there are no compatibility issues if use this approach.
You can use elevation to add shadows to any view
<TextView
android:id="#+id/myview"
...
android:elevation="2dp"
android:background="#drawable/myrect" />
Refer this for more information
For those using a CoordinatorLayout with the Bottom Navigation Bar (or BottomAppBar), you can use the following to attach a shadow above the bar:
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="#drawable/shadow"
app:layout_anchor="#+id/toolbar"
app:layout_anchorGravity="top"/>
Obviously, replace the #+id/toolbar with the id of the Bottom Navigation Bar
For those using Material Component - this has been fixed by com.google.android.material:material:1.1.0-alpha09.
Available since 1.1.0-alpha05 : https://github.com/material-components/material-components-android/releases/tag/1.1.0-alpha05
Use android:elevation="4dp" to set elevation shadow.
Also, do not forget to set clipChildren="false" on your main layout, otherwise, the shadow will be overwritten.
So I want to add a divider/separator at the bottom of the action bar in android, I have achieved this in pre lollipop Api's using windowContentOverlay like this
<item name="android:windowContentOverlay">#drawable/line</item>
and this is the drawable line
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:height="1dp"/>
<solid android:color="#android:color/darker_gray"/>
</shape>
and this is the graphical output that I have achieved and want in the newer android versions
I have tried to create a view of width 1dp and adding it to the activity xml but and removing the shadow, but this is not practical because It would require me to do this in all the views that uses the action bar.
This is my output in lollipop right now, this gives me a shadow, and if I remove it, the line separator wont appear.
how can I achieve the same look as in pre lollipop?