English 中文(简体)
图像按钮( Android) 的触摸反馈
原标题:Touch feedback for ImageButton (Android)

我正在为 ICS 开发一个应用程序。 我喜欢在动作栏中按钮对用户触摸( 周围的蓝光) 的反馈方式, 是否有简单的方法可以添加相同的图像按钮反馈?

Something like this, but with ImageButton: enter image description here

问题回答

是的,进入你的SDK。

导航到平台 & gt; 和roid-15 & gt; data- gt; 区域

您现在处于系统中的 Res 文件夹中。 如果您在可提取文件夹中搜索, 您应该能够找到代表默认系统按钮的 xml 选择器。 该选择器应该引用存储在其他可提取文件夹中的一些图像。 选择一个分辨率, 然后进入其文件夹并找到所有所需的图像 。

一旦您掌握了所有所需要的资源, 您就可以把它们包含在您自己的工程中。 然后在按下其它图像时, 使用您自己的选择器来显示 。

我不确定您要追求的效果, 但我认为如果您将 btn_ default_ holo_ pressed. 9. png 设置为在 scr 中显示图像的图像视图背景, 它应该与外部的蓝色条相仿。 如果选择者选择您可以在按键动作中实现这一点 。

如果您只是试图添加反馈

将绘图用作图像按钮背景 。

    <ImageButton
        android:id="@+id/btn_show_filter_dialog"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:background="@drawable/ic_filter_state"/>

为您的图像按钮创建可绘图文件 :

ic_ filter_state.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_enabled="false"
        android:drawable="@drawable/ic_filter_disable" />
    <item
        android:state_pressed="true"
        android:state_enabled="true"
        android:drawable="@drawable/ic_filter_click" />
    <item
        android:state_focused="true"
        android:state_enabled="true"
        android:drawable="@drawable/ic_filter_roll" />
    <item
        android:state_enabled="true"
        android:drawable="@drawable/ic_filter_solid" />
</selector>

用于反馈, 您只需要状态_ pressed=“ true” 和状态_ paped=“ true” 绘图

Here is an example with a vector drawable, but you can add your own drawable. Change the fillColor column for each state:

ic_ filter_sound.xml:

<vector android:alpha="1" android:height="24dp"
    android:viewportHeight="512" android:viewportWidth="512"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#ffffff" android:pathData="M487.976,0H24.028C2.71,0 -8.047,25.866 7.058,40.971L192,225.941V432c0,7.831 3.821,15.17 10.237,19.662l80,55.98C298.02,518.69 320,507.493 320,487.98V225.941l184.947,-184.97C520.021,25.896 509.338,0 487.976,0z"/>
</vector>

I think this might be what you re looking for: Image in Canvas with touch events

图像按钮和图像视图彼此相似。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签