【问题标题】:Android shape button strippedAndroid 形状按钮被剥离
【发布时间】:2016-11-02 07:47:08
【问题描述】:

我想在背景中构建一个具有 3 种不同颜色的按钮,就像附加的图像一样,但我不知道如何使用形状来做到这一点

感谢您的帮助。

【问题讨论】:

  • 为什么不使用图像作为背景?
  • 你想要这个背景上方的按钮吗?
  • @LucaNicolett with image 我必须适应每个屏幕,形状更适合表演
  • @mitesh viradiya 是的,我想要一个按钮
  • 你能发布你真正想要的 UI 图像吗

标签: android button


【解决方案1】:

使用 ImageButton 并将上图用作该按钮的背景:

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

【讨论】:

  • 如何用形状做到这一点
  • 谢谢 Drv,但我想用形状来做
【解决方案2】:

首先在drawable文件夹中创建一个带有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>

比你想要它使用的任何地方都像

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

在这里你可以根据你的要求改变角度,开始结束和中心颜色

【讨论】:

  • 谢谢,其实我不想用渐变,我只需要3种颜色,也许我需要创建3种形状,但我不知道如何使它们成为对角线
  • 只需将角度设为 45 或 135,使其变为对角线
  • 我已经试过了,它给出了很多没有条纹的渐变色,我只需要3个条纹色,中间什么都没有
  • 我认为您必须使用 9-patch 图像才能根据您的要求进行扩展。
  • stackoverflow.com/questions/4457030/… 使用此链接而不是告诉我它的工作与否
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
  • 2016-08-16
  • 1970-01-01
  • 2017-05-11
  • 1970-01-01
相关资源
最近更新 更多