0x开头的颜色值和#开头的颜色值的区别以及转化
生活随笔
收集整理的這篇文章主要介紹了
0x开头的颜色值和#开头的颜色值的区别以及转化
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
以0x開頭的顏色值和#開頭的顏色值都是16位進制的
他們的0x開頭的顏色值一般后面跟8位例如:0xfffefefe ,0x后面跟著前2個ff一般代表透明,后面跟著的6位和
#后面跟著6位相同, 目前自己是這樣大致理解的,相互可很好轉化,
例如 0x : 0xfffefefe,
????????? #? :#fefefe
他們2個顏色是相同的
他們的用法
?#開頭的比較常用在xml布局中
0x開頭比較常用的代碼的布局中。
下面一段例子
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.leon.color.MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="50dp" android:text="按鈕一" android:gravity="center" android:textColor="#fefefe" android:background="#FF4081"/> <TextView android:id="@+id/btn2" android:layout_marginTop="30dp" android:layout_width="match_parent" android:layout_height="50dp" android:text="按鈕2" android:gravity="center"/> <TextView android:id="@+id/btn3" android:layout_marginTop="30dp" android:layout_width="match_parent" android:layout_height="50dp" android:text="按鈕3" android:gravity="center"/> </LinearLayout>顯示效果如下
代碼
btn2=findViewById(R.id.btn2); btn2.setTextColor(0xfffefefe); btn2.setBackgroundColor(0xffFF4081); btn3=findViewById(R.id.btn3); btn3.setTextColor(Color.parseColor("#fefefe")); btn3.setBackgroundColor(Color.parseColor("#FF4081"));
運行后的效果如下
按鈕3 三0x 轉為#的顏色的
總結
以上是生活随笔為你收集整理的0x开头的颜色值和#开头的颜色值的区别以及转化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 惠州是属于那个城市的?
- 下一篇: 子宫内膜异位症不孕吗