Change Button Text Color When Pressed

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:

  1. It's not closed with </synth>

  2. If you don't set opaque="true" in it, by default your JButton will be transparent (i.e. your background won't be visible).

  3. I'm not entirely sure why, but for the foreground font color to change on state change you need to use TEXT_FOREGROUND instead of FOREGROUND 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>

Sample Image Sample Image

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 .

Sample Image



Related Topics



Leave a reply



Submit