Comments (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.
Excellent, thanks for the clarification ;-)
from image-support.
That worked for me. Your Android knowledge is impressive, Ivan! спасибо
from image-support.
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)
- Compiling gradle error HOT 2
- Migration from jCenter HOT 3
- strings.xml in library project causes bug for app using localized strings HOT 1
- Can we apply custom text?! HOT 2
- How to circle image?
- Any API to hide the badge
- Show/Hide count zero HOT 3
- minSdkSupport HOT 5
- Any Proguard Rules? HOT 1
- Any milestone to support AndroidX? HOT 2
- Can we add animation to the badge HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from image-support.