Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom button: change style when pressed

I created button with some shadow using a style:

<style name="test">
  <item name="android:shadowColor">#FFFFFF</item>
  <item name="android:shadowRadius">1</item>
  <item name="android:shadowDx">1</item>
  <item name="android:shadowDy">1</item>
</style>

This applies a white shadow on the button's text in its normal state. I was just wondering if anyone knows if there is a way to remove this shadow when the button is a pressed state. In other words, is there a way to apply another style when the button is in another (pressed) state?

Thanks in advance!

edit

bold.xml:

<resources>
    <style name="bold_text">
        <item name="android:textStyle">bold</item>
    </style>
</resources>

button.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/test_pressed"
              style="@style/bold_text"
          android:state_pressed="true"/>
    <item android:drawable="@drawable/test_focused"
          android:state_focused="true"/>
    <item android:drawable="@drawable/test_normal"/>
</selector>

my layout:

<Button
        ...
        android:background="@drawable/button"/>
like image 238
user440308 Avatar asked Sep 10 '10 04:09

user440308


People also ask

How do you style a click button?

Unfortunately, there is no :click pseudo selector. If you want to change styling on click, you should use Jquery/Javascript. It certainly is better than the "hack" for pure HTML / CSS.

How do you keep active CSS style after clicking a button?

:active denotes the interaction state (so for a button will be applied during press), :focus may be a better choice here. However, the styling will be lost once another element gains focus.

How do I change the button style on a press in react native?

To change button style on press in React Native, we can wrap our button with the TouchableHighlight component. to define the touchProps object that we use to set the props of TouchableHighlight . We set onHideUnderlay to a function that runs when the underlay is hidden.


1 Answers

You want a ColorStateList http://developer.android.com/guide/topics/resources/color-list-resource.html

like image 113
Nathan Schwermann Avatar answered Oct 27 '22 06:10

Nathan Schwermann