【问题标题】:How to get the color of view background in hexadecimal?如何以十六进制获取视图背景的颜色?
【发布时间】:2017-06-25 19:58:41
【问题描述】:

如何获得视图的颜色。如果没有办法,请为它编写代码。

【问题讨论】:

  • 你们有任何形式的颜色吗?
  • 请参考此链接stackoverflow.com/a/6540378/3946958 ..在此处提问之前,请正确搜索该主题
  • 如何设置view的颜色,android:background?
  • 不确定您是否要求这样的东西:Get background color of a Layout
  • @RavindraKushwaha 我搜索但我没有找到任何答案,所以我在这里问。

标签: android colors


【解决方案1】:

如果你使用view.setBackgroundColor()方法来设置view的颜色, 视图将自动创建一个ColorDrawable 实例来设置视图, 你只需要调用int color = ((ColorDrawable)view.getBackground()).getColor() 来检索颜色。 如果要获取十六进制格式的颜色值,只需调用 'Integer.toHexString(color)'

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2018-06-06
    • 2012-09-21
    • 2011-08-25
    • 1970-01-01
    • 2019-07-20
    • 2015-06-23
    • 2014-03-03
    • 2013-06-07
    • 2016-04-02
    相关资源
    最近更新 更多