安卓:一个按钮添加徽章绘的角落 [英] Android: Adding badge to corner of drawable on a button

查看:239
本文介绍了安卓:一个按钮添加徽章绘的角落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是添加徽章图标(圈,中间有一个数字),以按钮的绘制的最佳方式?

What is the best way to add a badge icon (Circle with a number in it) to a button's drawable?

在绘制只是一个形象。我希望会有改变我在用的作为按钮可绘制,也许它设置为具有我的形象在右上角的形状,中间绘制另一种方式。我将需要更新编程形状的文本。

The drawable is just an image. I was hoping there would be a way to change what I am using as the buttons drawable, and perhaps set it to another drawable that has my image in the middle with a shape on the top right. I will need to update the text of the shape programatically.

下面是我的按钮现在:

<Button
     android:id="@+id/SpecialsMenuButton"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
     android:textColor="#FFFFFF"
     android:text="@string/specials_tab_title"
     android:background="@drawable/menu_button"
     android:padding="4dp"
     android:drawableBottom="@drawable/collections_labels"
     android:textAppearance="?android:attr/textAppearanceSmall"
     android:layout_weight="1" />

我还创建了一个圆圈徽章:

I also created a circle badge:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="oval">
  <solid
    android:color="#F00" />
  <stroke
    android:width="2dip"
    android:color="#FFF" />
  <padding
    android:left="5dip"
    android:right="5dip"
    android:top="5dip"
    android:bottom="5dip" />
</shape>

我想尽可能方便地更换安卓的东西,将我的形象与图像的右上角的形状drawableBottom 。请问我能做到这一点作为一个绘制否则我将不得不这样做的按钮之外吗?

I want to as easily as possible replace the android:drawableBottom with something that will have my image with the shape in the top right corner of the image. Will I be able to do this as a drawable or will I have to do this outside of the button?

谢谢!

推荐答案

如果你想把它当作一个可绘制你必须创建一个位图,你画出的圆圈和数字到按钮的形象。

If you want it as a Drawable you have to create a Bitmap where you draw the circle and the number onto the image of the button.

不过,我会做这样的:将徽章作为的ImageView 的TextView 您的按钮上方,这样你就可以轻松地编辑的文本的TextView

But I would do it like this: Place the badge as an ImageView and a TextView above your button, so you can easily edit the text of the TextView

这篇关于安卓:一个按钮添加徽章绘的角落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆