Meow bottom navigation is a design bottom navigation which is used by most of the apps which want to make a better ui ux design for their application. I have provided a simple project below, you can easily implement meow bottom navigation into your project by following this article step by step. If you dont know what is meow bottom navigation the you can watch below image. So Lets Start
This Main Activity is using as a splesh screen. You can leave this activity integraion if you did not need or you have already added this into your project.
main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
MainActivity.java
package com.study.meow;
import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.text.style.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.text.*;
import org.json.*;
import android.content.Intent;
import android.net.Uri;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.DialogFragment;
public class MainActivity extends AppCompatActivity {
private Intent i = new Intent();
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.main);
initialize(_savedInstanceState);
initializeLogic();
}
private void initialize(Bundle _savedInstanceState) {
}
private void initializeLogic() {
i.setClass(getApplicationContext(), HomeActivity.class);
startActivity(i);
}
@Deprecated
public void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}
@Deprecated
public int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
@Deprecated
public int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
@Deprecated
public int getRandom(int _min, int _max) {
Random random = new Random();
return random.nextInt(_max - _min + 1) + _min;
}
@Deprecated
public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}
@Deprecated
public float getDip(int _input) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}
@Deprecated
public int getDisplayWidthPixels() {
return getResources().getDisplayMetrics().widthPixels;
}
@Deprecated
public int getDisplayHeightPixels() {
return getResources().getDisplayMetrics().heightPixels;
}
}
home.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/base"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" />
<LinearLayout
android:id="@+id/trash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal" />
<LinearLayout
android:id="@+id/linear3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="#BDBDBD"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="#42A5F5"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/layout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="#DCE775"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" />
</LinearLayout>
<com.study.meow.MeowBottomNavigation
android:id="@+id/meow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom" />
</FrameLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
empty.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:orientation="horizontal" />
</LinearLayout>
HomeActivity.java
package com.study.meow;
import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.*;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.text.style.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.text.*;
import org.json.*;
import android.widget.LinearLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.DialogFragment;
public class HomeActivity extends AppCompatActivity {
private Toolbar _toolbar;
private AppBarLayout _app_bar;
private CoordinatorLayout _coordinator;
private final static int ID_HOME = 1;
private final static int ID_EXPLORE = 2;
private final static int ID_MESSAGE = 3;
private FrameLayout main;
private LinearLayout base;
private LinearLayout trash;
private LinearLayout linear3;
private MeowBottomNavigation meow;
private LinearLayout layout1;
private LinearLayout layout2;
private LinearLayout layout3;
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.home);
initialize(_savedInstanceState);
initializeLogic();
}
private void initialize(Bundle _savedInstanceState) {
_app_bar = findViewById(R.id._app_bar);
_coordinator = findViewById(R.id._coordinator);
_toolbar = findViewById(R.id._toolbar);
setSupportActionBar(_toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v) {
onBackPressed();
}
});
main = findViewById(R.id.main);
base = findViewById(R.id.base);
trash = findViewById(R.id.trash);
linear3 = findViewById(R.id.linear3);
meow = findViewById(R.id.meow);
layout1 = findViewById(R.id.layout1);
layout2 = findViewById(R.id.layout2);
layout3 = findViewById(R.id.layout3);
}
private void initializeLogic() {
FrameLayout rl = new FrameLayout(this); FrameLayout.LayoutParams lparams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); rl.setLayoutParams(lparams); main.removeAllViews(); rl.addView(base); rl.addView(meow); main.addView(rl);
_viewPager();
meow.add(new MeowBottomNavigation.Model(ID_HOME, R.drawable.home));
meow.add(new MeowBottomNavigation.Model(ID_EXPLORE, R.drawable.msg));
meow.add(new MeowBottomNavigation.Model(ID_MESSAGE, R.drawable.gear));
meow.setOnShowListener(new MeowBottomNavigation.ShowListener() { @Override public void onShowItem(MeowBottomNavigation.Model item) {String name; switch (item.getId()) {
case ID_HOME:
_first();
break;
case ID_EXPLORE:
_second();
break;
case ID_MESSAGE:
_third();
break;
} }});
meow.setOnClickMenuListener(new MeowBottomNavigation.ClickListener() { @Override public void onClickItem(MeowBottomNavigation.Model item)
{switch (item.getId()) {
case ID_HOME:
_first();
break;
case ID_EXPLORE:
_second();
break;
case ID_MESSAGE:
_third();
break;
}
}});
meow.setOnReselectListener(new MeowBottomNavigation.ReselectListener() { @Override public void onReselectItem(MeowBottomNavigation.Model item) {
} });
meow.show(ID_HOME, true);
}
public void _first() {
viewPager.setCurrentItem(0);
}
public void _second() {
viewPager.setCurrentItem(1);
}
public void _third() {
viewPager.setCurrentItem(2);
}
public void _viewPager() {
viewPager = new androidx.viewpager.widget.ViewPager(this);
viewPager.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
MyPagerAdapter adapter = new MyPagerAdapter();
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(0);
base.addView(viewPager);
viewPager.addOnPageChangeListener(new androidx.viewpager.widget.ViewPager.OnPageChangeListener() {
public void onPageSelected(int position) {
if (viewPager.getCurrentItem() == 0) {
meow.show(ID_HOME, true);
}
else {
if (viewPager.getCurrentItem() == 1) {
meow.show(ID_EXPLORE, true);
}
else {
if (viewPager.getCurrentItem() == 2) {
meow.show(ID_MESSAGE, true);
}
}
}
}
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override public void onPageScrollStateChanged(int state) {
}
});
tabLayout = new com.google.android.material.tabs.TabLayout(this);
tabLayout.setTabGravity(tabLayout.GRAVITY_FILL);
}
private class MyPagerAdapter extends androidx.viewpager.widget.PagerAdapter {
public int getCount() {
return 3;
}
@Override public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.empty, null);
LinearLayout container = (LinearLayout) v.findViewById(R.id.linear1);
if (position == 0) {
ViewGroup parent = (ViewGroup) layout1.getParent();
if (parent != null) {
parent.removeView(layout1);
}container.addView(layout1);
} else if (position == 1) {
ViewGroup parent = (ViewGroup) layout2.getParent();
if (parent != null) {
parent.removeView(layout2);
}
container.addView(layout2);
} else if (position == 2) {
ViewGroup parent = (ViewGroup) layout3.getParent();
if (parent != null) {
parent.removeView(layout3);
}
container.addView(layout3);
}
collection.addView(v, 0);
return v;
}
@Override public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
trash.addView((View) view);
}
@Override public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);}
@Override public Parcelable saveState() {
return null;
}
}
androidx.viewpager.widget.ViewPager viewPager;
com.google.android.material.tabs.TabLayout tabLayout;
private void foo() {
}
@Deprecated
public void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}
@Deprecated
public int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
@Deprecated
public int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
@Deprecated
public int getRandom(int _min, int _max) {
Random random = new Random();
return random.nextInt(_max - _min + 1) + _min;
}
@Deprecated
public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}
@Deprecated
public float getDip(int _input) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}
@Deprecated
public int getDisplayWidthPixels() {
return getResources().getDisplayMetrics().widthPixels;
}
@Deprecated
public int getDisplayHeightPixels() {
return getResources().getDisplayMetrics().heightPixels;
}
}
Here we have added
Thank you for visiting our blog. If you face any problem while implement this source code into your project you can contact us for solving your errors. We will try to help you as soon as possible. You can easily make your app professional by using meow bottom source code into your project.
0 Comments