【问题标题】:Need to allow users to select color from sqllite database需要允许用户从 sqlite 数据库中选择颜色
【发布时间】:2017-04-24 00:21:06
【问题描述】:

我需要将颜色存储在 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>

我认为颜色会显示为图像或图标,并且选择将添加到数据库中的用户文件中?

【问题讨论】:

  • 我不太确定你在问什么。您发布的代码似乎与您描述的完全不同。

标签: android sqlite listview colors


【解决方案1】:

我假设您想将颜色存储在可转换为 android 颜色的数据库中。

你必须使用

Color.parseColor(String colorString);

...数据库中字符串的格式

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

从数据库中获取颜色字符串,使用 Color.parseColor(...) 将其作为颜色检索,并将 imageview 的颜色设置为返回的颜色。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多