Code Monkey home page Code Monkey logo

Comments (4)

nikartx avatar nikartx commented on August 23, 2024 4

Hi Chris,
Yes, of course, it possible. For example, you need to create a layout where will be added ImageBadgeView.
action_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:layout_gravity="center">

    <ru.nikartm.support.ImageBadgeView
        android:id="@+id/ibv_icon"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        app:ibv_badgeValue="80"
        app:ibv_badgeTextSize="8sp"
        app:ibv_fixedBadgeRadius="9dp"
        app:ibv_badgeTextStyle="bold"
        app:ibv_badgeTextColor="#222222"
        app:ibv_badgeColor="#ffffff"
        app:ibv_badgeLimitValue="false"
        android:tint="@color/colorAccent"
        android:src="@drawable/ic_delete" />

</FrameLayout>

Then you need to add a menu item
menu.xml

<menu 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">

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never" />

    <item
        android:id="@+id/action_del"
        android:title="Delete"
        app:actionLayout="@layout/action_layout"
        app:showAsAction="ifRoom"/>

</menu>

And finally, you need to add one method in Activity to find you a badge counter:

    private ImageBadgeView badgeView;

    .....

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        final MenuItem menuItem = menu.findItem(R.id.action_del);
        badgeView = menuItem.getActionView().findViewById(R.id.ibv_icon);
        badgeView.setBadgeValue(17);

        return super.onPrepareOptionsMenu(menu);
    }

Hope this help! :)

from image-support.

ChrisWoodard avatar ChrisWoodard commented on August 23, 2024 1

Excellent, thanks for the clarification ;-)

from image-support.

pleasespammelater avatar pleasespammelater commented on August 23, 2024 1

That worked for me. Your Android knowledge is impressive, Ivan! спасибо

from image-support.

divinsmathew avatar divinsmathew commented on August 23, 2024

Hey.. I'm losing the title toast that appears on long pressing a menu item, when I set a custom actionLayout. Is there a way to get the toast back?

from image-support.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.