Nifty TextField - how to change color?

How do I change the background color (which defaults to red) in the Nifty-GUI textfield control element? backgroundColor and color don’t seem to have an effect on the textfield. Only selectioncolor which changes the text’s color.



Thanks!

As far as I know, you’ll need to create a style document and then include it in your main document.



Example style document: (a modification of the nifty textfield black-style)



[xml]

<?xml version=“1.0” encoding=“UTF-8”?>

<nifty-styles xmlns=“http://nifty-gui.sourceforge.net/nifty-styles-1.3.xsd” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty-styles-1.3.xsd http://nifty-gui.sourceforge.net/nifty-styles-1.3.xsd”>



<style id=“nifty-textfield#field”>

<attributes childLayout=“center” visibleToMouse=“true” childClip=“true” backgroundColor="#666f" padding=“0px,2px” />

<effect>

<onActive name=“border” color="#222f" post=“true” inset=“1px” />



<!-- This should change the regular colour -->

<onFocus name=“colorBar” color="#800f" post=“true” inset=“1px” />



<!-- Rollover effect -->

<onHover name=“changeMouseCursor” id=“textFieldCursor” />

<onHover name=“border” color="#822f" post=“true” />



<!-- These two change the overlay when the field is disabled -->

<onEnabled name=“renderQuad” startColor="#2228" endColor="#2220" post=“true” length=“150” />

<onDisabled name=“renderQuad” startColor="#2220" endColor="#2228" post=“true” length=“150” />

</effect>

</style>

</nifty-styles>

[/xml]



Then below your [xml]<useStyles filename=“nifty-default-styles.xml” />[/xml] line, add:

[xml]<useStyles filename=“Interface/path-to-document/textfield-style-document.xml” />[/xml]



Hope that helps a bit (and hope it works too, I didn’t try it out just then)



(Edit: the link finder in this text editor must execute before the xml formatter…)

2 Likes