简体   繁体   English

Android形状按钮被剥离

[英]Android shape button stripped

I want to build a button with 3 different color in the background like the attached image, and I have no idea how to do that with shapes 我想在背景中构建一个具有3种不同颜色的按钮,如附图,我不知道如何使用形状

在此输入图像描述

Thank you for you help. 谢谢你的帮助。

Use ImageButton and use above image as background of that button: 使用ImageButton并使用上面的图像作为该按钮的背景:

 <ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:src="@drawable/YOUR_BTN_IMG"/>

1st make a xml file in drawable folder with bg1 name and put this code 首先使用bg1名称在可绘制文件夹中创建一个xml文件并放入此代码

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="90"
        android:centerColor="#4CAF50"
        android:endColor="#2E7D32"
        android:startColor="#b5e7b7"
        android:type="linear" />
</shape>

than where ever you want it use like 比你希望它使用的地方

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:src="@drawable/bg1"/>

here u change angle,start end and center color as per your requirement 在这里你可以根据你的要求改变角度,开始结束和中心颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM