【问题标题】:Adding multiple images and text in a button在一个按钮中添加多个图像和文本
【发布时间】:2018-08-19 08:24:10
【问题描述】:

我现在可以拥有一个包含单个图像图标和文本的按钮,如下所示(红色方块是图像):

<Button
    android:id="@+id/btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@drawable/shadow"
    android:drawableLeft="@drawable/redsquare"
    android:drawablePadding="6dp"
    android:text="Text goes here"
    android:textColor="@android:color/white"
    android:textSize="14dp"
    android:textAllCaps="false"
    android:gravity="left|center" />

但是,我希望有如下所示的按钮(两个红色小方块是两个不同的图像):

我尝试在按钮中添加另一个可绘制对象,但结果与预期不符。请问如何才能达到与上面按钮相同的结果?

【问题讨论】:

  • 最简单的方法是在布局 XML 中定义 UI,并将这一行添加到父布局:android:theme="@android:style/Widget.Button"。我认为RelativeLayout 会是这里最好的。
  • 任何细节将不胜感激!

标签: android android-button


【解决方案1】:

更好的方法是使用custom button 或自定义视图,并将ripple effectcustom button selector 添加到视图中。

【讨论】:

  • 我正在尝试在按钮上添加ImageView,但无法显示图像。你知道为什么吗?
猜你喜欢
  • 1970-01-01
  • 2015-11-24
  • 2015-07-08
  • 1970-01-01
  • 1970-01-01
  • 2018-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多