安卓:设置自定义梯度按钮 [英] Android: Setting up custom gradient for button

查看:112
本文介绍了安卓:设置自定义梯度按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">    
    <solid android:color="#EAEAEA"/>    

    <corners android:bottomLeftRadius="5dip"
                android:topRightRadius="5dip"
                android:topLeftRadius="5dip"
                android:bottomRightRadius="5dip"
    />
</shape>

如何设置我的梯度图像的背景为我的按钮。我看到一个属性梯度,但不能看到拿着背景,它的属性。

How can i set my gradient image as background for my button. I see a property gradient, but cannot see any attributes holding background in it.

注意:我非常新的Andr​​oid开发

Note: I am Very new Android development.

推荐答案

我不知道你向我们展示了XML具有梯度做。你可以在你的绘制一个XML文件中定义渐变文件夹:

I am not sure what the XML you showed us has to do with gradients. You can define a gradient in an XML file in your drawable folder:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#FFFFFFFF" 
        android:endColor="#FFD9D9D9"
        android:angle="270"
     />
    <corners android:bottomLeftRadius="5dip"
             android:topRightRadius="5dip"
             android:topLeftRadius="5dip"
             android:bottomRightRadius="5dip"
    />
</shape>

(例如,它保存为 my_gradient.xml

然后在您的布局xml文件,你可以有:

Then in your layout xml file you can have:

<Button android:id="@+id/ButtonStart"
    android:layout_width="100dp" android:layout_height="wrap_content"
    android:background="@drawable/my_gradient"
    android:textColor="@color/white" android:textSize="14sp"
    android:textStyle="bold" android:text="@string/game_start"/>

这篇关于安卓:设置自定义梯度按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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