- Home /
Background of GUI.TextField disappears when using a GUIStyle
When I add a GUIStyle to my GUI.TextField, the dark bakground of the TextField disappears and the TextField seems to be invisible. Is there any way to keep the background but still use a GUIStyle?
value = GUI.TextField(new Rect(25, 25, 200, 30), value, 10, guiStyle);
Answer by Phles · May 30, 2014 at 11:33 AM
Hey there, you could grab the background properties from the default text field GUIStyle, you could do something like...
public GUIStyle customGUIStyle;
bool hasAssignedStyleProperties = false;
void OnGUI()
{
if (!hasAssignedStyleProperties)
{
customGUIStyle.normal.background = GUI.skin.textField.normal.background;
customGUIStyle.active.background = GUI.skin.textField.active.background;
customGUIStyle.hover.background = GUI.skin.textField.hover.background;
customGUIStyle.focused.background = GUI.skin.textField.hover.background;
hasAssignedStyleProperties = true;
}
//do GUI stuff here...
}
Hope this helps.
Phill
Answer by chen_fly · Aug 16, 2021 at 07:12 AM
new style like:
GUIStyle s = new GUIStyle(EditorStyles.textField);
Your answer
Follow this Question
Related Questions
Single-line GUI.TextField with custom GUIStyle 3 Answers
GUI custom textfield cursor rendering 2 Answers
How can I change text alignment for GUI? 1 Answer
What's the difference between Normal and OnNormal in GUIStyle 2 Answers
Can change the shape of a GUI button/box/label to fit the shape of an object? 1 Answer