- 6 years ago
Tap bar menu is used instead of tabs and menus in Android. It covers only small space of app because is only one tab or button is visible by default. If users click it expand to more vertically or horizontally with material design animation effect. It is better to use at the bottom of the screen instead of bottom tab layout or you can use instead of dropdown/popup menu or options menu.
In this tutorial, you will learn to implement tap bar menu in your Android application or game with animation effect. Following are the simple steps to implement tap bar menu in Android.
First you have to add compile 'com.github.tosslife:foldingtabbar:1.0.0' dependencies in your app build.gradle file. Build.gradle file will look like below.
build.gradle
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
testCompile 'junit:junit:4.12' | |
compile 'com.android.support:appcompat-v7:23.1.0' | |
compile 'com.android.support:design:23.1.0' | |
compile 'com.github.tosslife:foldingtabbar:1.0.0' | |
} |
After adding gradle dependencies open your app XML layout file and then add com.srx.widget.TabBarView inside any layouts. Your XML layout file will looks like below.
res/layout/ tab_bar_folding_android_menu.xml
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<com.srx.widget.TabBarView | |
android:id="@+id/folding_android_tab_menu" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentTop="true" | |
android:layout_marginTop="16dp" /> | |
<com.srx.widget.TabBarView | |
android:id="@+id/foldingTabBarView" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:layout_marginBottom="16dp" /> | |
</RelativeLayout> |
In Java activity file we control all things like we add menu icons, animation effect and also control onClick event. Following is the complete code of Java activity file; you can paste it in your Java activity file.
src/ TabBarFoldingAndroidMenu.java
package viralandroid.com.androidmaterialdesigntutorial; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import com.srx.widget.TabBarView; | |
public class TabBarFoldingAndroidMenu extends AppCompatActivity { | |
TabBarView tabBarMenuView, foldingTabBarMenuView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.tab_bar_folding_android_menu); | |
tabBarMenuView = (TabBarView) findViewById(R.id.foldingTabBarView); | |
foldingTabBarMenuView = (TabBarView) findViewById(R.id.folding_android_tab_menu); | |
// main button icon | |
tabBarMenuView.setMainBitmap(R.drawable.ic_plus); | |
// Set the position corresponding to the menu button icons and icons on both sides | |
tabBarMenuView.bindBtnsForPage(0, R.drawable.ic_action_attach, R.drawable.ic_action_edit, R.drawable.ic_action_attach); | |
tabBarMenuView.bindBtnsForPage(1, R.drawable.ic_action_edit, R.drawable.ic_action_edit, R.drawable.ic_action_attach); | |
tabBarMenuView.bindBtnsForPage(2, R.drawable.ic_action_attach, R.drawable.ic_action_edit, R.drawable.ic_action_attach); | |
tabBarMenuView.bindBtnsForPage(3, R.drawable.ic_action_edit, R.drawable.ic_action_edit, R.drawable.ic_action_attach); | |
tabBarMenuView.initializePage(0); | |
tabBarMenuView.setOnTabBarClickListener(onTabBarClickListener); | |
// main button icon | |
foldingTabBarMenuView.setMainBitmap(R.drawable.ic_plus); | |
// Set the position corresponding to the menu button icons and icons on both sides | |
foldingTabBarMenuView.bindBtnsForPage(0, R.drawable.ic_action_attach, R.drawable.ic_action_edit, R.drawable.ic_action_attach); | |
foldingTabBarMenuView.bindBtnsForPage(1, R.drawable.ic_action_edit, R.drawable.ic_action_edit, R.drawable.ic_action_attach); | |
foldingTabBarMenuView.bindBtnsForPage(2, R.drawable.ic_action_attach, R.drawable.ic_action_edit, R.drawable.ic_action_attach); | |
foldingTabBarMenuView.bindBtnsForPage(3, R.drawable.ic_action_edit, R.drawable.ic_action_edit, R.drawable.ic_action_attach); | |
foldingTabBarMenuView.initializePage(0); | |
foldingTabBarMenuView.setOnTabBarClickListener(onFoldingTabBarClickListener); | |
} | |
private TabBarView.OnTabBarClickListener onTabBarClickListener = new TabBarView.OnTabBarClickListener() { | |
@Override | |
public void onMainBtnsClick(int position, int[] clickLocation) { | |
// Click event on the menu | |
} | |
@Override | |
public void onMainBtnsClick(int position) { | |
// Click event on the menu | |
} | |
@Override | |
public void onLeftBtnClick(int page) { | |
// Click event on the menu | |
} | |
@Override | |
public void onRightBtnClick(int page) { | |
// Click event on the menu | |
} | |
}; | |
private TabBarView.OnTabBarClickListener onFoldingTabBarClickListener = new TabBarView.OnTabBarClickListener() { | |
@Override | |
public void onMainBtnsClick(int position, int[] clickLocation) { | |
// Click event on the menu | |
} | |
@Override | |
public void onMainBtnsClick(int position) { | |
// Click event on the menu | |
} | |
@Override | |
public void onLeftBtnClick(int page) { | |
// Click event on the menu | |
} | |
@Override | |
public void onRightBtnClick(int page) { | |
// Click event on the menu | |
} | |
}; | |
} |
Now run your Animated Android Tap Bar Menu Example application and click on the plus button you will see other more option with animation effect. You can use button icon according to your needs and control on click event.
- 6 years ago
folding tab bar menu for Android. This is a menu library.You can easily add a nice animated tab menu to your app.
<dependency>
<groupId>com.github.tosslife</groupId>
<artifactId>foldingtabbar</artifactId>
<version>1.0.0</version>
<type>aar</type>
</dependency>
add in build.gradle:
//Wait bintray audit ...
compile 'com.github.tosslife:foldingtabbar:1.0.0'
After adding the gradle dependencies from above you can go to your XML layout and add the following code for a TabBarView:
<com.srx.widget.TabBarView
android:id="@+id/tabBarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
To set some basic settings to use the following java-code:
//
ObtainTabBarView TabBarView tabBarView = (TabBarView) findViewById(R.id.tabBarView); //
Set the main button icon???????tabBarView.setMainBitmap(R.drawable.icon_main); //
The settings menu corresponds to the location button icon and the icons on both sides???????tabBarView.bindBtnsForPage(0, R.drawable.icon_menu, R.drawable.icon_left, R.drawable.icon_right); //
Set the initial default selection???????tabBarView.initializePage(0); //
Add listen???????ertabBarView.setOnTabBarClickListener(onTabBarClickListener); //
Listener callback???????private OnTabBarClickListener onTabBarClickListener = new OnTabBarClickListener() { @Override public void onMainBtnsClick(int position, int[] clickLocation) { //
Click the menu???????} @Override public void onMainBtnsClick(int position) { //
Click the menu???????} @Override public void onLeftBtnClick(int page) { //
Click the button on the left side of the corresponding menu???????} @Override public void onRightBtnClick(int page) { //
Click the right button on the corresponding menu???????} };
Hot Questions