具有形状背景或图像的 Android 按钮 [英] Android buttons with shape background or image

查看:50
本文介绍了具有形状背景或图像的 Android 按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Android 应用程序中创建一个按钮,该按钮将使用我选择的颜色和一个加号作为其文本.

I want to create a button in an Android application which will be round with a color of my choosing and a plus sign as its text.

创建上述描述的图像并将其设置为背景图像更好(在空间,效率等方面),还是使用颜色制作形状并将其添加为背景更好?

Is it better (in terms of space, efficiency etc.) to create an image of the above description and set it as a background image, or it it better to make a shape with a color and add that as a background?

推荐答案

请试试下面的代码.

drawable 文件夹中创建一个 background.xml 并粘贴此代码.

create a background.xml in drawable folder and paste this code.

`

<solid android:color="@color/colorPrimary"></solid>

<stroke
    android:width="2dp"
    android:color="@color/colorPrimary"></stroke>

<padding
    android:left="5dp"
    android:right="5dp"
    android:top="5dp"></padding>

<corners android:radius="5dp"></corners>

`

布局

                   ` <ImageView
                        android:layout_gravity="center_vertical"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:background="@drawable/image" />


                </LinearLayout>`

这篇关于具有形状背景或图像的 Android 按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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