how to change the font color, font size, and button color in React
You write inline style...
<Panel style={{color:'red'}}>
or
<Panel className="sample">
in your style.css file just use
.sample {
your style here....
}
or else
<Panel className={styles.sample}>
then write your style inside
.sample{style here...}
Using a button to change the color of text
All you need to do is change this :
style={[styles.welcome, {color: undefined}]}
To
style={[styles.welcome, {color : this.state.color }]}
Please check : WORKING DEMO
how to change the color and font-family in react info banner
import
import { Provider as AlertProvider } from 'react-alert'
then,
childalert.show(<div style={{ 'color': 'blue', 'fontFamily':'arial' }}>
No changes were done to the ${project.projectName} project
</div>)
Change font color with TouchableHighlight
Here is a functional way
First, create useState then manipulate it on onPressIn/onPressOut
const TouchableHighlightExample = () => {
const [BtnColor, setBtnColor] = useState("red");
return (
<View>
<TouchableHighlight onPressIn={()=>setBtnColor("blue")} onPressOut={()=>setBtnColor("red")}>
<View>
<Text style={{color: BtnColor}}>Touch Here</Text>
</View>
</TouchableHighlight>
</View>
);
}
React JS How to change font color in element other than clicked button onClick?
You messed up some variable names and misunderstood how React works.
First, you can't query and HTML element and execute setState
because this is a React function. This function is not accessible from within the HTML document.
Second, your first approach with changing a state variable with the button click and mapping this variable to the color of the list elements is correct, but you mixed up the names:
This is your onChangeMethod
:
onChange = () => {
if (this.state.color == 'blue'){
this.setState({ color: 'green' });
}
else {
this.setState({ color: 'blue' });
}
}
Here you are mapping the state variable to the color property:
<li className={(item.name === this.state.name ? 'right' : 'left')}
style={{ color: this.state.font }}
key={item.id}
id={item.id}>
{item.name}: {item.message}
</li>
You are setting state.color
in theonChange
function, but you are referencing state.font
in you list element, instead change style
to the following:
style={{ color: this.state.color }}
React Native change Button Text color
You can use a Button from react-native like this and can also pass the color prop.
Button
onPress={onPressLearnMore}
title="Click Me"
color="#841584"
/>
For complex and custom buttons you can create it by your own styles using Touchables which are given by react-native you don't have to use any third-party libraries for that.
Example:
<TouchableOpacity style={{ here you can specify custom styles for button container }} onPress={gotoDashboard}>
<Text style={{here you can specify text styles}}>Button Text Here</Text>
// You can add there as many components according to your designs.
</TouchableOpacity>
change button color react native
The react Button
component renders the native button on each platform it uses. Because of this, it does not respond to the style
prop. It has its own set of props.
The correct way to use it would have been
<Button color="#ff5c5c" title="I'm a button!" />
You can see the documentation at https://facebook.github.io/react-native/docs/button.html
Now, say you do want to make super customizable button, for that you'll have to use views and touchable opacity. Something along the lines of this.
<TouchableOpacity onPress={...}>
{... button markup}
</TouchableOpacity>
You'll wrap that up in your own button component and use it.
Related Topics
How to Change Colour of Text Based on Its Value When a Page Initially Loads
Onclick JavaScript to Make Browser Go Back to Previous Page
How to Delete a Localstorage Item When the Browser Window/Tab Is Closed
How to Pass the Checked and Unchecked Value of Checkboxes in Component.Ts File in Angular
Javascript Blob Filename Without Link
Select Li Element With Arrow Keys (Up and Down) Using JavaScript (Jquery)
Sequelize How to Check If Entry Exists in Database
How to Select All Textframes in Document, and Retrieve the Text in Adobe Indesign
How to Clear the Focus in JavaScript
Reactjs - How to Update Nested and "Normal" State Properties
Cannot Access Json Object Property Returns Undefined
How to Display an Iframe on Button Click
How to Apply CSS to Parent Using Child Selector - With CSS or Angular 2
Easiest Way to Open a Download Window Without Navigating Away from the Page
Draw a Connecting Line Between Two Elements
How to Array Filter With Multiple Condition in JavaScript