徽章计数浮动动作按钮
我想在Android中的浮动动作按钮的面前显示徽章。我使用Framelayout来实现这一目标。我的代码在这里,
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/send_button"
android:layout_toLeftOf="@+id/send_button"
android:layout_toStartOf="@+id/send_button"
android:layout_gravity="end|bottom"
android:id="@+id/frameLayout">
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/listen_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:backgroundTint="#e3e3e3" />
<TextView
android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:textColor="#FFF"
android:textSize="10sp"
android:textStyle="bold"
android:background="@drawable/badge_circle"
android:layout_gravity="right|bottom"
android:layout_alignBottom="@+id/frameLayout"
android:layout_toLeftOf="@+id/frameLayout"
android:layout_toStartOf="@+id/frameLayout" />
</FrameLayout>
我在Fab下方获得了计数徽章,如下所示,如下所示
我需要计数徽章才能在晶圆厂。
I would like to show count badge in front of Floating Action Button in android. I used FrameLayout in order to achieve that. My code is here
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/send_button"
android:layout_toLeftOf="@+id/send_button"
android:layout_toStartOf="@+id/send_button"
android:layout_gravity="end|bottom"
android:id="@+id/frameLayout">
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/listen_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:backgroundTint="#e3e3e3" />
<TextView
android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:textColor="#FFF"
android:textSize="10sp"
android:textStyle="bold"
android:background="@drawable/badge_circle"
android:layout_gravity="right|bottom"
android:layout_alignBottom="@+id/frameLayout"
android:layout_toLeftOf="@+id/frameLayout"
android:layout_toStartOf="@+id/frameLayout" />
</FrameLayout>
I get the count badge below the FAB, as shown below
I need the count badge to be in front of the FAB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您可以使用 badgedrawable 由材料组件库提供。
类似:
当前(
1.3.0-Alpha02
)半径,但是您可以在项目中覆盖此尺寸(dimens.xml
):You can use the
BadgeDrawable
provided by the Material Components Library.Something like:
Currently (
1.3.0-alpha02
) there isn't a method to change the radius, but you can override this dimen in your project (dimens.xml
):对于此问题,解决方案是
Android:hevation =“ 7dp”
。但是您正在寻找类似的东西,然后使用波纹管代码:For this problem solution is
android:elevation="7dp"
. But you are looking for something like this then use bellow code:我使用 counterfab库实现这一目标。
它与将其添加到XML布局文件中一样简单,而不是常规
floatingActionButton
和调用counterfab.setCount(10);
(请参阅使用示例在这里)。I used the CounterFab library to achieve this.
It is as simple as adding it to your XML layout file instead of the regular
FloatingActionButton
and callingcounterFab.setCount(10);
(See usage example here).正如丹尼尔(Daniel)所建议的那样,您不应在浮动动作按钮中添加徽章。但是,如果您确实必须这样做,请尝试将此属性添加到您的文本视图中:
As suggested by Daniel, you should not add badges to Floating Action Buttons. However, if you really have to do it, try adding this property to your TextView:
可以通过提供自定义样式的浮动样式来简单地使用
textView
。One can simply use
TextView
by giving custom style for floating.尝试一下:
Give it a Try :
你可能想尝试这个
you might wanna try this
我已经使用了约束布局,希望它对
你们任何人。
I have managed using constrain layout , I hope it will be helpful to
any of you .
尝试此更改:
try this changes: