change button text color when pressed
See the section called State List in this bit of documentation...Drawable Resources.
You can define two different Button
xml files one for the transparent 'default' state and another with the button as Red for your 'pressed' state. You then define a selector
which switches the drawable resources in the different states.
EDIT: As per devunwired's comment the Color State List resource is probably more suitable for just changing colours rather than the drawable itself.
How to set text color in submit button?
.button{ font-size: 13px; color:green;}
<input type="submit" value="Fetch" class="button"/>
How to change the text button color on press in flutter?
int index = -1
Color enableColor = //your color
Color disableColor = //your color
onPressed: () {
//onPressed for button 1
setState((){
index = 0;
});
},
onPressed: () {
//onPressed for button 2
setState((){
index = 1;
});
},
onPressed: () {
//onPressed for button 3
setState((){
index = 2;
});
},
now set color in your widget
color: index == 0 ? enableColor : disableColor //this is for 1 button color
color: index == 1 ? enableColor : disableColor //this is for 2 button color
color: index == 2 ? enableColor : disableColor //this is for 3 button color
How to change button text color and background color while button is pressed
There are some issues in your Synth
file:
It's not closed with
</synth>
If you don't set
opaque="true"
in it, by default yourJButton
will be transparent (i.e. your background won't be visible).I'm not entirely sure why, but for the foreground font color to change on state change you need to use
TEXT_FOREGROUND
instead ofFOREGROUND
key.
I changed some colors from your file as they weren't too visible, but your file should look something like:
<synth>
<style id="basicStyle">
<font name="Verdana" size="16" />
<state>
<color value="#eeeeee" type="BACKGROUND" />
<color value="#000000" type="FOREGROUND" />
</state>
</style>
<bind style="basicStyle" type="region" key=".*" />
<style id="button_style">
<opaque value="true" />
<insets top="4" left="4" right="4" bottom="4" />
<state>
<color value="blue" type="TEXT_FOREGROUND" />
<color value="#ffffff" type="BACKGROUND" />
</state>
<state value="PRESSED">
<color value="white" type="TEXT_FOREGROUND" />
<color value="#aaaaaa" type="BACKGROUND" />
</state>
</style>
<bind style="button_style" type="region" key="button" />
</synth>
How to change text color when button pressed in flutter?
Code is working fine for me. I can only guess what's the mistake.
Maybe your pressed
variable is declared inside the build()
method and not inside the State
class.
Try to move the declaration to class level and it should work fine
Android customized button; changing text color
Create a stateful color for your button, just like you did for background, for example:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Focused and not pressed -->
<item android:state_focused="true"
android:state_pressed="false"
android:color="#ffffff" />
<!-- Focused and pressed -->
<item android:state_focused="true"
android:state_pressed="true"
android:color="#000000" />
<!-- Unfocused and pressed -->
<item android:state_focused="false"
android:state_pressed="true"
android:color="#000000" />
<!-- Default color -->
<item android:color="#ffffff" />
</selector>
Place the xml in a file at res/drawable folder i.e. res/drawable/button_text_color.xml. Then just set the drawable as text color:
android:textColor="@drawable/button_text_color"
Change Button Text Color When Clicked in IOS
Change button type in storyboard from system to custom .
Related Topics
Imageview of Png Doesn't Appear (Maybe It's Too Big)
How to Control Navigationview Margin Between Menu Items
How to Close the Current Fragment by Using Button Like the Back Button
How to Get Context in Android Mvvm Viewmodel
How to Transfer from One Fragment to Another in Android
Refresh/Reload/Re Instantiate a Fragment in an Android Tab System
Adb.Exe Not Found After Installing Android Studio
How to Use Python to Execute Adb Commands
How to Check If a Value Exists Already in a Firebase Data Class Android
How to Go Back to Previous Fragment from Activity
Why Livedata Observer Is Being Triggered Twice for a Newly Attached Observer
Android No on Screen Keybord ( Only Voice )
Limitations on Opening Pdf File in Android
Error Androidmanifest.Xml Doesn't Exist or Has Incorrect Root Tag
Android:Get Current Date and Time from Firebase