首页  >  问答  >  正文

android中如何将int颜色代码转换成十六进制

代码是这样:setBackgroundColor(0x33ffffff);、
但是xml文件就不能写0x...
xml文件是这样:<solid android:color="#33ffffff" />

我想把0x33ffffff转换成# 开头的颜色,我尝试过直接去掉0x换成#,发现颜色不一样,网上也查不到方法,最多只能查到十六进制转RGB,或者RGB转十六进制。

天蓬老师天蓬老师2715 天前985

全部回复(3)我来回复

  • ringa_lee

    ringa_lee2017-04-17 17:42:32

    颜色转换是对的,估计是控件透明度叠加问题。如果无透明度不会产生色差。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#33FFFFFF" >
    
        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="#33FFFFFF"
            android:text="@string/hello_world"
            android:textColor="#33FFFFFF" />
    
    </RelativeLayout>

    这段代码直接加载,你会发现textview的背景色有突出的一块

    回复
    0
  • 迷茫

    迷茫2017-04-17 17:42:32

    0x33ffffff也是十六进制吧,找找转换算法或者相应的软件转换

    回复
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:42:32

    请使用Color.parseColor("#33ffffff")方法来获取转后的值, 然后设置到背景上

    回复
    0
  • 取消回复