Add elevation to BottomNavigationView - android

Here's what my bottom navigation bar in XML looks like:
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/white"
app:itemBackground="#color/primary"
app:elevation="8dp"
app:menu="#menu/main_activity_bottom_nav"/>
If I remove app:itemBackground="#color/primary", the elevation shows properly, but the moment I add that back in, it disappears.

I think that the problem is not use the app:itemBackground property, but the color that you set as itemBackground.
If I change my app:itemBackground color to white, it works fine, and I can show the shadow above and bottom of the BottomNavigationView. But if I use my primary color (blue), I can see the shadow only on the bottom of my BottomNavigationView.
I think that the easiest way to solve this problem, is create your own shadow and set it above of your BottomNavigationView. It's very simple. This post describes what you have to do.
If you encounter some problems, let a comment below.
I hope that this answer can help you!!
Good luck!!

Related

How to Change BottomNavigationBar attributes?

how to disable magnify and modify font_size of selected tab in BottomNavigationBar Android, I just wanna change the tab's color, don't magnify the tab, what should i do, thanks!
is there any attribute to change some attribute in this widget?
<com.ashokvarma.bottomnavigation.BottomNavigationBar
android:id="#+id/mainTabBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:animateLayoutChanges="false"
android:background="#color/white"
android:splitMotionEvents="false"
app:bnbActiveColor="#color/colorPrimary"
app:bnbBackgroundColor="#color/white"
app:bnbInactiveColor="#color/gray"
app:bnbMode="mode_fixed"
tools:override="true"/>
That BottomNavigationBar is a custom component and probably has its own method of styling or inheriting a style. Can you please share how it works or references to the documentation of the component? Thank you!

Android support design floating action button elevation not visible for colors other than white

I'm using compile 'com.android.support:design:23.1.1' and android.support.design.widget.FloatingActionButton to create a FAB.
When the background tint color is white the elevation (shadow) is very visible.
But for other colors the elevation not visible.
Here is my code:
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/create_floating_button"
app:elevation="6dp"
app:borderWidth="0dp"
android:clickable="true"
app:backgroundTint="#color/colorAccent"
app:rippleColor="#color/colorAccentLight"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Beside this problem, even with white color, the button doesn't seem like the ones in google material design spec.
Check this for example (the shadow's direction is down):
What am I doing wrong?
Make sure you have a specific layout-v21 file where you replace app:elevation with android:elevation. After API 21 you need to do this to maintain a good compatibility.

FloatingActionButton no border?

I cannot find a way to get a FAB with no border. For example when I try:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fab"
android:background="#android:color/transparent"
android.support.design:fabSize="normal"
android:adjustViewBounds="true"
style="#style/Fab"/>
I get:
Notice the border still around the FAB. I have tried adjustViewBounds="true" and android:background="#android:color/transparent" both of which are the suggested solutions for getting rid of the border on an ImageView (which FAB extends) but neither work. How can I get rid of this border?
Note: all #style/Fab does is position the button, nothing to do with border.
Just add app:borderWidth="0dp" in your layout file:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fab"
app:borderWidth="0dp"
android:background="#android:color/transparent"
android.support.design:fabSize="normal"
android:adjustViewBounds="true"
style="#style/Fab"/>
There is also added advantage of adding this, it fixes the problem of square FAB in API<15.
Update: The latest update for android support does not need borderwidth=0dp to fix the square FAB.
Answer to comment by #Zvi
To make background of the button transparent, use this line :
app:backgroundTint="#00FFFFFF"
The hash code for transparent background is : #00FFFFFF
To change the color of the icon inside the button, use this :
android:tint="#800080"
#800080 is the hash code for purple
For accessing hash codes for different colors, go here: http://www.color-hex.com/color-palettes/
Just copy the hash codes and paste it wherever you want it.
Turns out it was
app:borderWidth="0dp"
How stupid of me. Thank you #Ranjith.
This somehow also added a shadow under the button:

How to change text color in Sliding tabs

I'm learning Android and don't understand how to change the color of the text in Sliding tabs of the Google Example SlidingTabs Colors:
https://developer.android.com/samples/SlidingTabsColors/project.html
I tried to write:
<com.example.android.common.view.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ddffffff"
android:textColor="#ffffffff">
But nothing happened.
Also text color didn't change when I used this :
#android:style/TextAppearance.Holo.Widget.ActionBar.Title
in my Theme.
There is whole library for page sliding tabs for colors.
You may wan to see this example.
https://github.com/astuetz/PagerSlidingTabStrip
There are many tutorial regarding changing color of page strip.

Transparent toolbar and statusbar

I have different activities in my project with listview in it. I am using app compact v7 and following material design.My requirement is to shown transparent toolbar and statusbar like iOS and when user will scroll the listeview towards up. listview should be visible behind the toolbar and actionbar. Please let me know how can i do this. I tried a lot of solution but could not achieve the desired o/p.
Styles
<item name="colorPrimaryDark">#android:color/transparent</item>
XML Layout
<android.support.v7.widget.Toolbar
android:id="#+id/my_awesome_toolbarAdd"
android:layout_height="56dp"
android:layout_width="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="#android:color/transparent" />
You can try this (don't do the optional step #5 in your case):
Unable to make toolbar transparent in Android

Categories

Resources