Android 将按钮内的图像与文本组合

Android 将按钮内的图像与文本组合,android,android-layout,Android,Android Layout,嗨,伙计们,我刚刚开始编写代码,目前正在学习android的xml和java。 我试着做一个按钮,上面写着目标,但不是O,而是一个球的图像,我试着在一个设计程序中制作一个图像,上面写着目标,里面有球的图标,然后用它作为按钮的图像背景,但它忽略了灰色,我计划将其改为绿色背景,这不是我真正想要的。 有没有一种方法可以将图像添加到包含文本的按钮中? 或者我应该在不同的软件中设计按钮,然后将其添加为按钮的背景吗 像Te~ImageHere~xt尝试使用android:drawableLeft=@mipm

嗨,伙计们,我刚刚开始编写代码,目前正在学习android的xml和java。 我试着做一个按钮,上面写着目标,但不是O,而是一个球的图像,我试着在一个设计程序中制作一个图像,上面写着目标,里面有球的图标,然后用它作为按钮的图像背景,但它忽略了灰色,我计划将其改为绿色背景,这不是我真正想要的。 有没有一种方法可以将图像添加到包含文本的按钮中? 或者我应该在不同的软件中设计按钮,然后将其添加为按钮的背景吗

像Te~ImageHere~xt

尝试使用android:drawableLeft=@mipmap/ic_launcher_round添加图像按钮

可以使用在文本之间添加可绘制的插入。下面是一个例子

  TextView textView=(TextView)findViewById(R.id.b1);
    Spannable span = new SpannableString("G OL");
    Drawable android = getResources().getDrawable(R.mipmap.ic_launcher);
    android.setBounds(0, 0, 50,50);
    ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE);
    span.setSpan(image, 1, 2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    textView.setText(span);
下面是输出。您可以修改边界。

是的,可能会重复,但我要完成的是将图像放在文本Te~imagehere~xt中间
android:drawableTop="@mipmap/ic_launcher_round"
android:drawableBottom="@mipmap/ic_launcher_round"
android:drawableRight="@mipmap/ic_launcher_round"
android:drawableLeft="@mipmap/ic_launcher_round"
android:drawableEnd="@mipmap/ic_launcher_round"
  TextView textView=(TextView)findViewById(R.id.b1);
    Spannable span = new SpannableString("G OL");
    Drawable android = getResources().getDrawable(R.mipmap.ic_launcher);
    android.setBounds(0, 0, 50,50);
    ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE);
    span.setSpan(image, 1, 2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    textView.setText(span);