Customizing JTextField in Synth - java

I need to change the text color in a JTextField when it gets focus, but it looks like just the state SELECTED works.
<style id="textfield">
<state value="SELECTED">
<color value="#87A0DC" type="TEXT_BACKGROUND"/>
<color value="#000000" type="TEXT_FOREGROUND"/>
</state>
<state value="FOCUSED">
<color value="#000000" type="TEXT_BACKGROUND"/>
<color value="#87A0DC" type="TEXT_FOREGROUND"/>
</state>
</style>
I already have tried with BACKGROUND and FOREGROUND either, but nothing has changed.
If anyone can help, Please.

Related

I can't get my color primary to match the buttons on my screen even though they are the same HEX color in Android Studio

I can't get my colors in my app to line up, even though they supposedly are the same hex code. What I did is I went into Sketch (where I exported and made the buttons) and used the program to get hex code, but as you can see from the picture (below that is not the same color.
https://imgur.com/a/pfcLgOm
Here is my code from my colors file and styles file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name= "color1"> #5AD7DB</color>
<color name= "color2"> #D53D96</color>
<color name= "color3"> #F27E33</color>
</resources>
<resources>
Here is my styles file
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/color1</item>
<item name="colorPrimaryDark">#color/color1</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="MyCustomHelpshiftTheme"
parent="Helpshift.Theme.Light.DarkActionBar">
<item name="colorAccent">#color/color2</item>
<item name="colorPrimary">#color/color1</item>
<item name="colorPrimaryDark">#color/color1</item>
</style>
<style name="Helpshift.Theme.Base" parent="MyCustomHelpshiftTheme"/>
</resources>
Try the below code in your colors.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="color1">#5AD7DB</color>
<color name="color2">#D53D96</color>
<color name="color3">#F27E33</color>
</resources>
Spaces removed where unnecessary..

Set color in button Android

I have a color define in colors.xml
<color name="gray">#9e9e9e</color>
I want to set the background color in my MainActivity I stablish a conditional that set the background depens the version of Android that the device has.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
cobro.setBackgroundColor(getResources().getColor(R.color.gray, getApplicationContext().getTheme()));
cobro.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.gray));
}
else
{
cobro.setBackgroundColor(getResources().getColor(R.color.gray));
}
Actually I am testing in Android Lollipop, so the color has to be setting with the if statement, but neither of two forms setting me the background color to my button work, any idea? could anybody tell me what is the correct form to set the background color?
On your Button XML, add an attribute like this
android:background="#color/yourColor"
But before doing that, you need to add yourColor inside your colors.xml file. The default value of colors.xml is below
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
Then just add yourColor there
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="yourColor">#yourColorCode</color>
</resources>
Use ContextCompat rather than deprecated getColor Method
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.L){
cobro.setBackground(R.drawable.btn_selector);
}else{
cobro.setBackground(R.drawable.btn_selector);
}
btn_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/login_selected" /><!-- pressed -->
<item android:state_focused="true"
android:drawable="#drawable/login_mouse_over" /> <!-- focused -->
<item android:drawable="#drawable/login" /><!-- default -->

Error: The markup in the document following the root element must be well-formed

i'm new to Android programming, and I have an error,can anybody help me and explain why i have the Error:The markup in the document following the root element must be well-formed? Here is my code. Thank you very much
<color name="puzzle_background">#ffe6f0ff </color>
<color name="puzzle_hilite">#ffffffff</color>
<color name="puzzle_light">#64c6d4ef</color>
<color name="puzzle_dark">#6456648f</color>
<color name="puzzle_foreground">#ff000000</color>
<color name="puzzle_hint_0">#64ff0000</color>
<color name="puzzle_hint_1">#6400ff80</color>
<color name="puzzle_hint_2">#2000ff80</color>
<color name="puzzle_selected">#64ff8000</color>
In XML documents only one element can be at the top level.
Wikipedia: Root element
Wrap your colors into something like :
<colors>
<color name="puzzle_background">#ffe6f0ff </color>
<color name="puzzle_hilite">#ffffffff</color>
<color name="puzzle_light">#64c6d4ef</color>
<color name="puzzle_dark">#6456648f</color>
<color name="puzzle_foreground">#ff000000</color>
<color name="puzzle_hint_0">#64ff0000</color>
<color name="puzzle_hint_1">#6400ff80</color>
<color name="puzzle_hint_2">#2000ff80</color>
<color name="puzzle_selected">#64ff8000</color>
</colors>

How do I use my own colors in android XML

I have an XML file I created in the res/value folder and try to reference it by writing
android:background="#colors/red"
and it does not work.
I also tried placing this file in the drawable folder but to no avail.
Refer to color resources with #color/name, not #colors/name.
For example, in res/values/whatever.xml:
<color name="your_color_name">#12345678</color>
Then in a layout xml:
android:background="#color/your_color_name"
Your color res file has to be under res/values/ (You may add it to a qualifier res/values folder though)
Add the color in this format:
<resources>
<color name="white">#ffffff</color>
</resources>
Refer to it using #color/white.
You can declare a color in your color.xml file like below,
<color name="aqua_blue">#6495ED</color>
And then use it below,
android:background="#color/aqua_blue"
easy way
android:background="#8EE8B5"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="yellow">#FFFF00</color>
<color name="fuchsia">#FF00FF</color>
<color name="red">#FF0000</color>
<color name="silver">#C0C0C0</color>
<color name="gray">#808080</color>
<color name="olive">#808000</color>
<color name="purple">#800080</color>
<color name="maroon">#800000</color>
<color name="aqua">#00FFFF</color>
<color name="lime">#00FF00</color>
<color name="teal">#008080</color>
<color name="green">#008000</color>
<color name="blue">#0000FF</color>
<color name="navy">#000080</color>
<color name="black">#000000</color>
</resources>
make one xml named colors.xml in res and add color names and codes as you want custum

How to color the background of the application in android

I added a color folder, with this xml file:
<?xml version="1.0" encoding="utf-8"?>
<item
xmlns:android="http://schemas.android.com/apk/res/android">
<color name="orange">#FF9912</color>
</item>
But when I put as the value in the screen_display.xml that i created in the values folder. It gives me a mistake:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme.Background" parent="#android:style/Theme">
<item name="android:windowNoTitle"> true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#colors/color/orange</item>
</style>
</resources>
UPDATE
<activity android:name=".EasyLearningActivity"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:theme="MyTheme.Background"...shows mistake, saying that Strying type inst allowed :(
>
pls chk out this
in values folder create two xml file first one
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="orange">#FF9912</color>
</resources>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme.Background" parent="#android:style/Theme">
<item name="android:windowNoTitle"> true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#color/orange</item>
</style>
</resources>
In manifest file:
<activity android:name=".EasyLearningActivity"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:theme="#style/MyTheme.Background"></activity>
It's #color, not #colors...
and are you setting the android:theme attribute for your application tag in the manifest to use MyTheme.Background?
You can't use directly string for android:theme.
You need to include one of the styles like **#style/**MyTheme.Background.
Thanks for the color.xml , finally after 7 hours of research and lots of frustration I now have a purple action bar like I wanted.
<color name="orange" type="color">#FF9912</color>
<color name="red" type="color">#FF0000</color>
<color name="blue" type="color">#FF33B5E5</color>
<color name="purple" type="color">#FFAA66CC</color>
<color name="green" type="color">#FF99CC00</color>
<color name="darkblue" type="color">#FF0099CC</color>
<color name="darkpurple" type="color">#FF9933CC</color>
<color name="darkgreen" type="color">#FF669900</color>
<color name="darkorange" type="color">#FFFF8800</color>
<color name="darkred" type="color">#FFCC0000</color>
<!--Black #000000 (0,0,0)
White #FFFFFF (255,255,255)
Red #FF0000 (255,0,0)
Lime #00FF00 (0,255,0)
Blue #0000FF (0,0,255)
Yellow #FFFF00 (255,255,0)
Cyan / Aqua #00FFFF (0,255,255)
Magenta / Fuchsia #FF00FF (255,0,255)
Silver #C0C0C0 (192,192,192)
Gray #808080 (128,128,128)
Maroon #800000 (128,0,0)
Olive #808000 (128,128,0)
Green #008000 (0,128,0)
Purple #800080 (128,0,128)
Teal #008080 (0,128,128)
Navy #000080 (0,0,12-->
<!--color name="orange" type="color">#FFFFBB33</color-->
<!--<color name="red" type="color">#FFFF4444</color-->

Categories

Resources