Android Create Bottom Navigation Animated

1. Project Structure

2. Gradle
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.bottomnavigation.animated"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
implementation 'com.google.android:flexbox:0.3.2'
}
3. Main Activity
package com.bottomnavigation.animated;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.bottomnavigation.animated.utils.Tools;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class MainActivity extends AppCompatActivity {
private TextView mTextMessage;
private BottomNavigationView navigation;
private View search_bar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_navigation_animated);
initComponent();
}
private void initComponent() {
search_bar = (View) findViewById(R.id.search_bar);
mTextMessage = (TextView) findViewById(R.id.search_text);
navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return true;
}
});
navigation.setSelectedItemId(R.id.action_clock);
((ImageButton) findViewById(R.id.bt_menu)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Tools.setSystemBarColor(this, R.color.grey_5);
Tools.setSystemBarLight(this);
}
}
4. Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_5">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="@dimen/spacing_mlarge"
android:src="@drawable/shape_circle"
app:tint="@color/grey_20" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="70dp"
android:layout_height="@dimen/spacing_middle"
android:background="@color/grey_20" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_middle"
android:background="@color/grey_20" />
<View
android:layout_width="40dp"
android:layout_height="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_middle"
android:background="@color/grey_20" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_large"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="@dimen/spacing_mlarge"
android:src="@drawable/shape_circle"
app:tint="@color/grey_10" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="100dp"
android:layout_height="@dimen/spacing_middle"
android:background="@color/grey_10" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_middle"
android:background="@color/grey_10" />
<View
android:layout_width="40dp"
android:layout_height="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_middle"
android:background="@color/grey_10" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_large"
android:layout_marginHorizontal="@dimen/spacing_medium"
android:gravity="center"
android:text="Bottom Navigation with animated icon"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
android:textColor="@color/grey_40" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<!-- search bar layout -->
<include
android:id="@+id/search_bar"
layout="@layout/include_card_view_search_bar" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="@color/indigo_600"
app:elevation="15dp"
app:itemIconTint="@color/color_state_white_2"
app:itemTextColor="@color/color_state_white_2"
app:menu="@menu/menu_bottom_navigation_animated" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_middle"
android:layout_marginBottom="@dimen/spacing_middle"
android:clipToPadding="false"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="3dp"
app:cardElevation="3dp"
app:cardUseCompatPadding="false"
app:layout_collapseMode="parallax">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:id="@+id/bt_menu"
android:layout_width="@dimen/spacing_xxlarge"
android:layout_height="@dimen/spacing_xxlarge"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/grey_60"
app:srcCompat="@drawable/ic_stack_menu" />
<TextView
android:id="@+id/search_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="Search"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
android:textColor="@color/grey_40" />
<ImageButton
android:layout_width="@dimen/spacing_xxlarge"
android:layout_height="@dimen/spacing_xxlarge"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/grey_60"
app:srcCompat="@drawable/ic_mic" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
5. Value
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:ns1="urn:oasis:names:tc:xliff:document:1.2">
<style name="Base.TextAppearance.AppCompat.Small">
<item name="android:textSize">@dimen/abc_text_size_small_material</item>
<item name="android:textColor">?android:attr/textColorTertiary</item>
</style>
<color name="grey_10">#e6e6e6</color>
<color name="grey_20">#cccccc</color>
<color name="grey_40">#999999</color>
<color name="indigo_600">#3949AB</color>
</resources>