2017-04-24 118 views
0

我需要將顏色存儲在sqllite數據庫中,並讓用戶選擇他們想要的字體顏色。
顏色將顯示在滾動視圖中,類似於顯示圖標選擇。 如何以這種方式向用戶顯示顏色?需要允許用戶從sqllite數據庫中選擇顏色

<LinearLayout 
      android:layout_width="200dp" 
      android:layout_height="50dp" 
      android:orientation="horizontal" 
      android:layout_marginRight="73dp" 
      android:layout_marginEnd="73dp" 
      android:layout_below="@+id/btnCreateAccount" 
      android:layout_alignRight="@+id/btnCreateAccount" 
      android:layout_alignEnd="@+id/btnCreateAccount"> 
      <ImageView 
       android:layout_width="50sp" 
       android:layout_height="50sp" 
       android:src="@mipmap/color1" 
       android:id="@+id/imgView1"/> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@mipmap/color2" 
       android:id="@+id/imgView2"/> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@mipmap/color3" 
       android:id="@+id/imgView3"/> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@mipmap/color4" 
       android:id="@+id/imgView4"/> 
     </LinearLayout> 

我會認爲顏色會顯示爲圖像或圖標,選擇將被添加到數據庫中的用戶文件?

+0

我不太清楚你在問什麼。您發佈的代碼似乎與您所描述的完全不同。 – nasch

回答

0

我假設你想將顏色存儲在可轉換爲android顏色的數據庫中。

你將不得不使用

Color.parseColor(String colorString); 

...其中在數據庫中的字符串的格式

#RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray' 

從數據庫中獲取的顏色字符串,使用Color.parseColor(.. )將其作爲顏色檢索,並將imageview的顏色設置爲返回的顏色。

相關問題