Reputation: 519
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?
Upvotes: 0
Views: 4397
Reputation: 759
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"
Upvotes: 2