.setBackgroundColor with Hex Color Codes AndroidStudio

Linus
View targetView;
targetView = (View)findViewById(R.id.mainlayout);

this works but

targetView.setBackgroundColor(Color.parseColor("#FFFFFF"));

and also this didn't work

targetView.setBackgroundColor(Color.pasrsehexString("#FFFFFF"));

Error: Cannot resolve method'parseColor(java.lang.String)'

and : Cannot resolve method'pasrsehexString(java.lang.String)'

Pleas can somebodey help me and by the way i'm using Android Studio.

Tom

There are two main classes for color handling in Java/Android.

This first one is from "plain" Java and can be found in java.awt.Color. This class supports converting a String into a color with the method decode. Example:

Color red = Color.decode("#FF0000");

The second class is for Android and can be found in android.graphics.Color. The conversion can be done with the method parseColor.

int red = Color.parseColor("#FF0000");

So you should check which kind of Color class you've imported to your project. I recommend using the Android version of Color for your case. If you've done that the statement targetView.setBackgroundColor(Color.parseColor("#FFFFFF")); should work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Regex for hex color codes in bbcode?

From Dev

How to multiply hex color codes?

From Dev

Regular Expressions to Search for Hex color codes

From Dev

Hex Color codes maybe causing CSS to not work

From Dev

Mapping RGB/hex color codes to general color categories

From Dev

How are 4 and 5 digit hex color codes represented?

From Dev

Convert hex color codes into HSL value and vice-versa?

From Dev

What should I use? Hex codes, RGB codes, or color names in code?

From Dev

setBackgroundColor changes color of more then the button

From Dev

Can you use hex color values with vt100 escape codes c++

From Dev

Firefox throwing error while reading #hex color codes inside inline SVG

From Dev

Can you use hex color values with vt100 escape codes c++

From Dev

UIToolbar setBackgroundColor doesn't fully change color

From Dev

UIToolbar setBackgroundColor doesn't fully change color

From Dev

setBackgroundColor(Color.WHITE) works in one part of the code, but setBackgroundColor(Color.RED) doesn't

From Dev

Plot a matrix of colour hex codes

From Dev

insert array of hex codes into an integer

From Dev

to send hex codes to serial port

From Dev

Android: Color codes

From Dev

Android: Color codes

From Dev

Transforming Color Codes in VBA

From Dev

powertop color codes

From Dev

Fragmented listview view.setBackgroundColor(Color.GREEN);

From Dev

setBackgroundColor with array stays gray, doesn't change color

From Dev

setBackgroundColor on a layout with a unique id also changes the color on other layouts

From Java

Use Hex color in SwiftUI

From Dev

Hex color code multiple #

From Dev

Ordering Color by Hex Value

From Dev

Lighten or darken a hex color

Related Related

HotTag

Archive