A lot of my work in XML has many colors to choose from and I cannot seem to find an extension or plugin for Android Studio that can choose a pick a color from an image source of my own choosing and apply it within my code. I am currently using Photoshop but unfortunately, it slows down my computer.
I have been using native colors and not my own. Eg:
<< ? xml version = "1.0"
encoding = "utf-8" ? >
<
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 = "@color/color_bg"
tools: context = "com.transcendencetech.juliospizzaprototype.SignInActivity" >
<
include
android: id = "@+id/header"
layout = "@layout/header"
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: layout_alignParentTop = "true"
android: layout_alignParentLeft = "true"
android: layout_alignParentStart = "true" / >
<
RelativeLayout
android: id = "@+id/my_tabs"
android: layout_width = "match_parent"
android: layout_height = "40dp"
android: layout_below = "@id/header"
android: background = "@android:color/black" >
<
View
android: id = "@+id/divider_view"
android: layout_width = "1dp"
android: layout_height = "match_parent"
android: layout_centerInParent = "true"
android: layout_margin = "2dp"
android: background = "@android:color/white" / >
<
Button
android: id = "@+id/pizza_list_bt"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_alignParentLeft = "true"
android: layout_alignParentStart = "true"
android: layout_toLeftOf = "@id/divider_view"
android: layout_toStartOf = "@id/divider_view"
android: background = "@android:color/black"
android: inputType = "textPersonName"
android: text = "List of Pizzas"
android: textColor = "@android:color/white" / >
<
Button
android: id = "@+id/deals_list_bt"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_alignParentEnd = "true"
android: layout_alignParentRight = "true"
android: layout_toEndOf = "@id/divider_view"
android: layout_toRightOf = "@id/divider_view"
android: background = "@android:color/black"
android: inputType = "text"
android: text = "List of Deals"
android: textColor = "@android:color/white" / >
<
/RelativeLayout>
<
ImageView
android: id = "@+id/pizza_list_iv"
android: layout_width = "match_parent"
android: layout_height = "150dp"
android: layout_below = "@id/my_tabs"
android: scaleType = "fitXY"
android: src = "@drawable/list_pizza_header" / >
<
ListView
android: id = "@+id/list_view"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: layout_below = "@id/pizza_list_iv"
android: divider = "@color/color_divider"
android: focusable = "true"
android: dividerHeight = "2dp"
android: layout_margin = "15dp" / >
<
include
layout = "@layout/footer"
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: layout_alignParentBottom = "true"
android: layout_alignParentLeft = "true"
android: layout_alignParentStart = "true" / >
<
/RelativeLayout>
3
Answers
If you mean that you want to use an eyedropper tool to measure the hex value (e.g. #ff0000) or the RGB value (e.g. rgb(255, 0, 0)) of a specific pixel, there are many websites that allow you to do this.
For example, if you search for ‘online color picker from image‘ on the web, many good sites come up. I use the first one that comes up on Google, Image Color Picker (you can find your own) which lets you either pick an image URL from the web or upload an image from your computer.
Hopes this helps!
Step #1: Define one or more color resources, such as in
res/values/colors.xml
:Step #2: Click the color swatch that appears in the resource editor gutter, to the left of the resource:
Clicking that swatch will bring up a color-picker dialog:
Step #3: Click the eyedropper tool, to the left of the color swatch bar in that dialog. This will bring up your typical sort of eyedropper view that follows your mouse pointer. Hover over the color you want to pick up, then click the left mouse button. Back in the dialog, click Choose to update the color resource to use that picked color.
Step #4: In your layout, use
@color/whatever_name_you_give_it
to reference the color, wherewhatever_name_you_give_it
is whatever name you give it.There are many websites available to help you pick image color. I personally use pickimagecolor.com as you even find the color shades which makes the work easier. It allows you to upload image from your computer and you can easily find the Hexadecimal, RGB() color and HSV color code. I just copy the color code and use it. It is a image color picker website but you can also use it to convert color code Hex to RGB , RGB to HEX and many more options are available. Hope it helps.