简体   繁体   English

按钮就像Android中的Imageview的点击效果一样

[英]Button like click effect for Imageview in android

I'm having an imageview which will navigate to another page once it is clicked. 我有一个imageview,一旦点击它将导航到另一个页面。 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? 所以我想要的是在点击图像时有一些效果(比如在普通按钮中)....任何人都可以帮助我吗?

use style="?android:borderlessButtonStyle" in the xml file. 在xml文件中使用style =“?android:borderlessButtonStyle” It will show android default click effect. 它将显示android默认点击效果。

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" 
    style="?android:borderlessButtonStyle"
    />

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>

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. 其中iv是你的imageview。

说到xml选择器,这里是你可以帮助xml选择器链接的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM