Created
January 17, 2017 19:21
-
-
Save adroitandroid/049101cf3fdb2901dc4af3e07e748172 to your computer and use it in GitHub Desktop.
Custom bottom navigation bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeActivity extends BaseBottomNavActivity { //thinned down sample implementation of the BaseBottomNavActivity above | |
private ActivityHomeBinding binding; | |
public static void start(Activity activity) { | |
Intent intent = new Intent(activity.getApplicationContext(), HomeActivity.class); | |
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); | |
activity.startActivity(intent); | |
} | |
public static Intent getStartIntent(Context context) { // if required in a service etc | |
Intent intent = new Intent(context, HomeActivity.class); | |
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); | |
return intent; | |
} | |
@Override | |
protected void initOnCreate(Bundle savedInstanceState) { | |
binding = DataBindingUtil.setContentView(this, R.layout.activity_home); | |
} | |
@Override | |
protected void onNavBarReselect() { | |
removeProfileFragmentIfAdded(); // sample method call | |
} | |
private boolean removeProfileFragmentIfAdded() { | |
boolean wasAdded = getSupportFragmentManager().popBackStackImmediate(); | |
if (wasAdded) { | |
mIsDataFetched.setValue(true); | |
setupActionBar(binding.layoutToolbar, getString(R.string.title_home), false); | |
binding.contentSwipeRl.setEnabled(true); | |
showToolbarIconFor(null); | |
removeViewProfileFragment(); | |
updateAddStoryFabVisibility(false); | |
} | |
return wasAdded; | |
} | |
@Override | |
protected int getCurrentBottomNavPosition() { | |
return CustomBottomNavigationBar.POSITION_HOME_TAB; | |
} | |
@Override | |
protected CustomBottomNavigationBar getBottomNavigationBar() { | |
return binding.bottomNavBar; | |
} | |
@Override | |
public void onBackPressed() { | |
boolean wasAdded = removeProfileFragmentIfAdded(); | |
if (!wasAdded) { | |
super.onBackPressed(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | |
<FrameLayout | |
android:layout_width="match_parent" | |
android:layout_height="@dimen/bottom_bar_with_shadow_height"> | |
<View | |
android:id="@+id/shadow_gradient" | |
android:layout_width="match_parent" | |
android:layout_height="@dimen/bottom_bar_with_shadow_height" | |
android:background="@drawable/shadow_gradient" /> | |
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<RadioGroup | |
android:id="@+id/bottom_bar_layout" | |
android:layout_width="match_parent" | |
android:layout_height="@dimen/bottom_bar_height" | |
android:layout_alignParentBottom="true" | |
android:background="@color/colorPrimaryDark" | |
android:elevation="4dp" | |
android:gravity="center" | |
android:orientation="horizontal"> | |
<com.adroitandroid.stitchastory.ui.RadioButtonPlus | |
android:id="@+id/home_tab_btn" | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1" | |
android:background="@null" | |
android:button="@drawable/ic_home" /> | |
<com.adroitandroid.stitchastory.ui.RadioButtonPlus | |
android:id="@+id/leaderboard_tab_btn" | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1" | |
android:background="@null" | |
android:button="@drawable/ic_leaderboard" /> | |
<com.adroitandroid.stitchastory.ui.RadioButtonPlus | |
android:id="@+id/activity_tab_btn" | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1" | |
android:background="@null" | |
android:button="@drawable/ic_activity" /> | |
<com.adroitandroid.stitchastory.ui.RadioButtonPlus | |
android:id="@+id/bookmarks_tab_btn" | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1" | |
android:background="@null" | |
android:button="@drawable/ic_collection_bookmarks" /> | |
<com.adroitandroid.stitchastory.ui.RadioButtonPlus | |
android:id="@+id/profile_tab_btn" | |
android:layout_width="0dp" | |
android:layout_height="match_parent" | |
android:layout_weight="1" | |
android:background="@null" | |
android:button="@drawable/ic_profile" /> | |
</RadioGroup> | |
</RelativeLayout> | |
</FrameLayout> | |
</layout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment