代码是这样:setBackgroundColor(0x33ffffff);、
但是xml文件就不能写0x...
xml文件是这样:<solid android:color="#33ffffff" />
我想把0x33ffffff转换成# 开头的颜色,我尝试过直接去掉0x换成#,发现颜色不一样,网上也查不到方法,最多只能查到十六进制转RGB,或者RGB转十六进制。
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
迷茫2017-04-17 17:42:32
0x33ffffff is also hexadecimal, look for the conversion algorithm or corresponding software conversion
大家讲道理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