Comments (5)
I stumbled upon this issue but found a (rather hacky) way to solve this without having to modifying the library yourself
If you use Kotlin in your project, you can use this extension function snippet
// Extensions
fun QBadgeView.setup(count: Int, targetView: View) {
this
.setBadgeNumber(count)
.setBadgeGravity(Gravity.TOP or Gravity.END)
// add other setter / options according to your own need
.bindTarget(targetView)
if (count == 0) {
val parent = this.targetView.parent
if (parent is ViewGroup) {
parent.children.forEach { child ->
if (child is QBadgeView) { child.isVisible = false }
}
}
}
}
// Usage
private fun setupView() {
// val count = someMethodToGetCount()
// val targetView = the view from findViewById / viewBinding / kotlin_synthetic
QBadgeView(context).setup(count, targetView)
}
Basically, we just simply set the BadgeView's visibility to GONE when our number / count is 0
val parent = this.targetView.parent // "this" is the BadgeView object
if (parent is ViewGroup) {
// Iterate the children to search for BadgeView object
parent.children.forEach { child ->
if (child is QBadgeView) {
child.isVisible = false // If it's a BadgeView, we set visibility to gone,
// isVisible is just a nicer way to do it from core-ktx library
// otherwise just use setVisibility( ... )
}
}
}
Hope this helpful
from badgeview.
me ,two
from badgeview.
me,too
from badgeview.
neither the hide method nor the 0 input can hide the badge...
该问题是因为重复创建了BadgeView。应该让BadgeView只创建一次。
from badgeview.
The problem is
if (mBadgeNumber < 0) {
mBadgeText = "";
in QBadgeView.java
@OverRide
public Badge setBadgeNumber(int badgeNumber) {
mBadgeNumber = badgeNumber;
if (mBadgeNumber < 0) {
mBadgeText = "";
} else if (mBadgeNumber > mMaxBadgeNumber) {
mBadgeText = mExact ? String.valueOf(mBadgeNumber) : mMaxBadgeNumber + "+";
} else if (mBadgeNumber > 0) {
mBadgeText = String.valueOf(mBadgeNumber);
} else {
mBadgeText = null;
}
measureText();
invalidate();
return this;
}
Try editing it in your source since apparently the developer ditched the project 2 years ago
from badgeview.
Related Issues (20)
- FloatingActionButton 设置Badage后,就不悬浮了。
- NavigationView如何使用BadgeView?
- setBadgeGravity 没法正常生效
- 当消息数量为0的时候,红点还是数值还是1 HOT 3
- 华为手机上不显示红点?
- ConstraintLayout 中子 控件 宽度为 0 , 2个 TextView 相互约束。 设置 BadgeView 导致控件显示错位
- 数字显示时,背景不是圆的
- mavenCentral() support HOT 1
- 大佬后期不维护了吗什么时候把仓库迁移mavenCentral
- 可以在PagerSlidingTabStrip中使用吗?有没有demo
- java.lang.ClassCastException: q.rorbin.badgeview.QBadgeView$BadgeContainer cannot be cast to android.widget.FrameLayout
- 如何解除小红点与View的绑定 HOT 1
- 新的需求
- 与 butterknife 结合使用,会在activity 销毁的时候崩溃,找不到控件
- 绑定的TargetView设置了View.GONE后Badge还在原来的位置,没有随TargetView的隐藏而隐藏
- constraintlayout中的textview显示不出来
- 小米8显示不了红点
- 重复调用的话红点的阴影会越来越重 最后变成黑色了
- app退到后台,红点不显示
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 badgeview.