繁体   English   中英

Android:将徽章添加到按钮上可绘制的角落

[英]Android: Adding badge to corner of drawable on a button

将徽章图标(带有数字的圆圈)添加到按钮的绘制中的最佳方法是什么?

可绘制对象只是图像。 我希望有一种方法可以更改我用作按钮可绘制对象的方式,并且可能将其设置为另一个可绘制对象,该对象的中间位置是我的图像,右上角是一个形状。 我将需要以编程方式更新形状的文本。

现在这是我的按钮:

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

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

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

我想尽可能轻松地将android:drawableBottom替换为将使我的图像形状在图像右上角的东西。 我将能够作为可绘制对象来执行此操作,还是必须在按钮之外执行此操作?

谢谢!

如果要将其作为可Drawable ,则必须创建一个Bitmap ,在其中将圆圈和数字绘制到按钮的图像上。

但我会这样做:将徽章分别作为ImageViewTextView放在按钮上方,以便您可以轻松地编辑TextView的文本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM