【问题标题】:How to give accent color to icon of imagebutton?如何为图像按钮的图标赋予强调色?
【发布时间】:2016-04-05 22:35:03
【问题描述】:

我正在按照材料设计教程和图标来开发应用程序,但我发现一个应用程序可以在单击时更改图标颜色。我也想这样做。我怎么能建造这样的东西?请帮我解决这个问题,按钮点击小吃栏的颜色也会改变。

谢谢

【问题讨论】:

    标签: android imagebutton android-imagebutton android-snackbar


    【解决方案1】:

    您可以使用 selector 来实现。

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true" android:drawable="resource when button is pressed"/>
        <item android:state_pressed="false" android:drawable="resource when button is not pressed"/>
    </selector>
    

    如果您想在按钮上应用该选择器,请按照此步骤操作。

    1. 制作资源(.xml)文件。
    2. 在资源标签内输入xml代码(选择器)。
    3. 像这样在按钮上设置背景:button.setbackground(@drawable/xml);

    【讨论】:

    • 这是一个图像按钮,图标设置为图像按钮。那么选择后如何改变图标的​​颜色呢?
    • 糟糕...我会尽快编辑答案。我写了&lt;selector&gt;标签,但它没有出现。
    【解决方案2】:

    尝试使用此选择器来更改要选择的图像或您的图像按钮

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed = "true"
        android:drawable="@drawable/your_icon_pressed"/>
    <item
        android:drawable="@drawable/your_icon"/>
    </selector>
    

    【讨论】:

      猜你喜欢
      • 2015-01-31
      • 2020-01-27
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多