Space-Navigation-View

Additional

Language
Java
Version
1.6.0 (Jan 29, 2017)
Created
Aug 11, 2016
Updated
Aug 11, 2019
Owner
Arman (armcha)
Contributors
Michał Seroczyński (mseroczynski)
Jorge Garrido (FireZenk)
Arman (armcha)
ankitpopli1891
Subhrajyoti Sen (SubhrajyotiSen)
Kogoro
Chris (nextdimension)
akiraspeirs
rvndbalaji
9
Activity
Badge
Generate
Download
Source code
APK file

Advertising

Maven:

<dependency>
  <groupId>com.github.armcha</groupId>
  <artifactId>SpaceNavigationView</artifactId>
  <version>1.6.0</version>
  <type>pom</type>
</dependency>

Setup and usage

Add the Space Navigation view to your layout

 <FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"> <...View .... android:layout_marginBottom="@dimen/view_bottom_margin" /> <com.luseen.spacenavigation.SpaceNavigationView android:id="@+id/space"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="bottom"/> </FrameLayout>

Add Space Navigation items.

SpaceNavigationView spaceNavigationView = (SpaceNavigationView) findViewById(R.id.space); spaceNavigationView.initWithSaveInstanceState(savedInstanceState); spaceNavigationView.addSpaceItem(newSpaceItem("HOME", R.drawable.yourDrawable)); spaceNavigationView.addSpaceItem(newSpaceItem("SEARCH", R.drawable.yourDrawable));

Use

initWithSaveInstanceState(savedInstanceState) and override onSaveInstanceState if you want to keep selected item position and badge on device rotation@Overrideprotectedvoid onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); spaceNavigationView.onSaveInstanceState(outState); }

Set onClick listener

 spaceNavigationView.setSpaceOnClickListener(newSpaceOnClickListener() { @OverridepublicvoidonCentreButtonClick() { Toast.makeText(MainActivity.this,"onCentreButtonClick", Toast.LENGTH_SHORT).show(); } @OverridepublicvoidonItemClick(intitemIndex, StringitemName) { Toast.makeText(MainActivity.this, itemIndex +""+ itemName, Toast.LENGTH_SHORT).show(); } @OverridepublicvoidonItemReselected(intitemIndex, StringitemName) { Toast.makeText(MainActivity.this, itemIndex +""+ itemName, Toast.LENGTH_SHORT).show(); } });

Set onLongClick listener

    spaceNavigationView.setSpaceOnLongClickListener(newSpaceOnLongClickListener() {
            @OverridepublicvoidonCentreButtonLongClick() {
                Toast.makeText(MainActivity.this,"onCentreButtonLongClick", Toast.LENGTH_SHORT).show();
            }

            @OverridepublicvoidonItemLongClick(intitemIndex, StringitemName) {
                Toast.makeText(MainActivity.this, itemIndex +""+ itemName, Toast.LENGTH_SHORT).show();
            }
        });