Button like click effect for Imageview in android

2020-07-24 05:43发布

I'm having an imageview which will navigate to another page once it is clicked. Right now when it is clicked user will not be getting any feel that it is clicked. So what i want is to have some effect (like in normal button) at the time of click on the image....can anyone help me?

4条回答
甜甜的少女心
2楼-- · 2020-07-24 05:53

Speaking about xml selector, here is the link which could you help xml selector link

查看更多
Lonely孤独者°
3楼-- · 2020-07-24 05:53

Assuming you are referring to physical not visible feel, use something like this to make a sound and provide haptic feedback:

    iv.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
    iv.playSoundEffect(SoundEffectConstants.CLICK);

where iv is your imageview.

查看更多
ゆ 、 Hurt°
4楼-- · 2020-07-24 05:57

Try a selector like this

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

    <item android:state_pressed="true"><shape>
            <solid android:color="#151B8D" />

            <stroke android:width="1dp" android:color="#151B8D" />

            <corners android:bottomLeftRadius="8dp" android:bottomRightRadius="0dp" android:topLeftRadius="0dp" android:topRightRadius="8dp" />

            <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
        </shape></item>
    <item><shape>
            <gradient android:angle="270" android:endColor="#151B8D" android:startColor="#151B8D" />

            <stroke android:width="1px" android:color="#000000" />

            <corners android:bottomLeftRadius="8dp" android:bottomRightRadius="0dp" android:topLeftRadius="0dp" android:topRightRadius="8dp" />

            <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
        </shape></item>

</selector>
查看更多
Emotional °昔
5楼-- · 2020-07-24 06:18

use style="?android:borderlessButtonStyle" in the xml file. It will show android default click effect.

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" 
    style="?android:borderlessButtonStyle"
    />
查看更多
登录 后发表回答