ShabanKamell / ViewBadger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ViewBadger

Add BADGE to any Android view at runtime.

Features

  • Optimized badge for TabLayout
  • Optimized badge for BottomNavigationView.
  • Add badge to any view.

Installation

Last Version

allprojects {
	repositories {
	...
	maven { url 'https://jitpack.io' }
	}
}

dependencies {
	implementation 'com.github.ShabanKamell:ViewBadger:LAST.VERSION'
}

Usage

BottomNavigationView

BadgeView badge = new ViewBadger().setupWithViewBottomNavigation(
                bottomNavigationView,
                1,
                this
        );

        badge.setText("1111");
        badge.show(true);

TabLayout

BadgeView badge = new ViewBadger().setupWithTabLayout(
                tabLayout,
                index,
                TabLayoutMode.WITH_TITLE_AND_ICON,
                getContext()
        );

        badge.setText("111");
        badge.setOnClickListener(v -> viewPager.setCurrentItem(index));
        badge.show(true);

Any View

Wrap the view with BadgeTarget

<com.sha.viewbadger.BadgeTarget
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

      <ImageView
         android:id="@+id/ivSquareLarge"
         android:layout_width="100dp"
         android:layout_height="100dp"
         android:layout_gravity="center"
         android:background="@drawable/btn_background"
         />

</com.sha.viewbadger.BadgeTarget>

Show the badge

BadgeView badge = new ViewBadger().setupWithView(
                getView().findViewById(view),
                R.id.root,
                isRound,
                getContext()
        );

        badge.setText("33");
        badge.setOnClickListener(v -> viewPager.setCurrentItem(index));
        badge.setPosition(position);
        badge.show(true);

Credit

jgilfelt/android-viewbadger

See 'app' module for the full code.

License

Apache license 2.0

About


Languages

Language:Java 100.0%