Home  >  Q&A  >  body text

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

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

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

天蓬老师天蓬老师2765 days ago1024

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 17:42:32

    The color conversion is correct, it is probably a problem of control transparency overlay. If there is no transparency, there will be no color difference.

    <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>

    This code is loaded directly, you will find that the background color of the textview has a prominent piece

    reply
    0
  • 迷茫

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

    0x33ffffff is also hexadecimal, look for the conversion algorithm or corresponding software conversion

    reply
    0
  • 大家讲道理

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

    Please use the Color.parseColor("#33ffffff") method to get the converted value, and then set it to the background

    reply
    0
  • Cancelreply