0

I have an ImageView in my application. When user Clicks the imageView I am supposed to show a border around the ImageView. This Border style I have it as a style called "myStyle" in my styles.xml.

I need to show this style only when the user clicks the image view. How can I do this?

ydnas
  • 519
  • 1
  • 12
  • 29
  • Go to this: [how-to-display-border-to-imageview](http://stackoverflow.com/questions/5841128/how-to-display-border-to-imageview) – M D Mar 05 '14 at 12:55
  • http://stackoverflow.com/questions/3241729/android-dynamically-change-style-at-runtime/6390025#6390025 –  Mar 05 '14 at 12:58
  • you need `selector` xml and set that as your background of your button – Shayan Pourvatan Mar 05 '14 at 13:02

1 Answers1

2

Well, i will advice you to get the border style info into an xml file and save it at the drawable folder - let's call it border_pressed.xml.

And then at the drawable folder create a file called, let's say, imagview_state.xml and put in it the next code -

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:drawable="@drawable/border_pressed" android:state_pressed="true"></item>

</selector>

and at the layout file - where the ImageView is- set it's background like that -

android:background="@drawable/imagview_state"
4this
  • 759
  • 4
  • 13
  • 27