在android中为按钮背景添加渐变色

在android中为按钮背景添加渐变色,android,Android,我有一个带有代码的渐变背景: <Button android:id="@+id/btn_signup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Login" android:background="@drawable/sel_btn_background"

我有一个带有代码的渐变背景

<Button android:id="@+id/btn_signup"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Login"
            android:background="@drawable/sel_btn_background"
            android:gravity="center"
            android:textSize="16sp"
            android:layout_marginTop="40dp"
            android:textColor="@android:color/white"/>

sel_btn_background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <gradient
            android:startColor="@color/bluegreen"
            android:endColor="@color/aqua_marine"
            android:angle="-270" />
</shape>

我得到结果

<Button android:id="@+id/btn_signup"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Login"
            android:background="@drawable/sel_btn_background"
            android:gravity="center"
            android:textSize="16sp"
            android:layout_marginTop="40dp"
            android:textColor="@android:color/white"/>

如何实现以下结果(左侧为浅色,右侧为深色)角度应增加什么值:


应该是360,请尝试以下操作:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#36d1d1"
        android:centerColor="#811010"
        android:endColor="#233308"
        android:angle="360" />
</shape>


相应地替换颜色值。我使用了完全不同的颜色来区分所有3种颜色

应该是360,请尝试以下操作:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#36d1d1"
        android:centerColor="#811010"
        android:endColor="#233308"
        android:angle="360" />
</shape>

相应地替换颜色值。我使用了完全不同的颜色来区分所有3种颜色

试试这个

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#278b79"
        android:centerColor="#32b39b"
        android:endColor="#38c7ad"
        android:angle="180" />
</shape>

试试这个

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#278b79"
        android:centerColor="#32b39b"
        android:endColor="#38c7ad"
        android:angle="180" />
</shape>

使用180角而不是-270角

使用180角而不是-270角


尝试改变不同的角度。尝试将angle更改为android:angle=“180”@kishanverma。。。你能把这个答案贴出来吗。。。。180工作完美Devrath sure up投票更改差角。尝试将angle更改为android:angle=“180”@kishanverma。。。你能把这个答案贴出来吗。。。。180很好用Devrath确定投我一票