How To Change Colored To Black And White(grayscale) When Touch In Android
I have Horizontal layout with dynamically add imageview using adding image on linear layout. and all horizontal view add scorllview vertically ||||||| when touch then change colore
Solution 1:
You can add background for layout in your xml file and set a custom layout for your background like this
android:background="@drawable/custombackground"
custombackground.xml
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_window_focused="false"android:state_enabled="true"android:color="your color code" /><itemandroid:state_window_focused="false"android:state_enabled="false"android:color="your color code" /><itemandroid:state_pressed="true"android:color="your color code" /><itemandroid:state_enabled="true"android:state_focused="true"android:color = "#00000000"/><itemandroid:state_enabled="true"android:color="your color code" /><itemandroid:state_focused="true"android:color="your color code" /><itemandroid:color="your color code" /></selector>
hope it will help you :)
Solution 2:
Basically,your requirement is to change the color of imageview when you touch it,for that you have to implement the color changing code in case MotionEvent.ACTION_DOWN:
for example the changing color is light gray
so the code will be
v.setBackgroundColor(Color.LTGRAY);
you can change the color according to your requirement
and after this, put the below code in case MotionEvent.ACTION_UP:
to change the color to default i.e transperent
v.setBackgroundColor(Color.TRANSPARENT);
Post a Comment for "How To Change Colored To Black And White(grayscale) When Touch In Android"