聚焦或单击时如何突出显示 ImageView?

How to highlight ImageView when focused or clicked?(聚焦或单击时如何突出显示 ImageView?)

本文介绍了聚焦或单击时如何突出显示 ImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个很好的例子是在 Twitter 启动屏幕(应用程序首次启动时看到的带有大图标的屏幕),或者当您聚焦应用程序图标时,甚至只是查看应用程序托盘.

A good example of this is either on the Twitter launch screen (the screen with the large icons that is seen when the application is first launch) or even just look at the application tray when you focus an application icon.

基本上,我需要突出显示 ImageView,其中突出显示的轮廓与 ImageView 中的图像一致,看起来就像是该图像的边框.我还想自定义突出显示以使其具有某种颜色并使其淡出.

Basically I need to highlight an ImageView where the highlight contours to the image within the ImageView and looks like it's a border to that image. I would also like to customize the highlight to have it be a certain color and for it to fade out.

谢谢,

帅气

推荐答案

你需要为ImageViewsrc属性分配一个状态列表drawable.换句话说,该状态列表对于选中、按下、未选中等会有不同的图像——这就是 Twitter 应用程序的工作方式.

You need to assign the src attribute of the ImageView a state list drawable. In other words, that state list would have a different image for selected, pressed, not selected, etc. - that's how the Twitter App does it.

如果你有一个 ImageView:

So if you had an ImageView:

<ImageView style="@style/TitleBarLogo"
            android:contentDescription="@string/description_logo"
            android:src="@drawable/title_logo" />

src 可绘制对象 (title_logo.xml) 如下所示:

The src drawable (title_logo.xml) would look like this:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/title_logo_pressed"/>
    <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/title_logo_pressed"/>
    <item android:state_focused="true" android:drawable="@drawable/title_logo_selected"/>
    <item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/title_logo_default"/>
</selector>

Google IO Schedule 应用程序就是一个很好的例子.

这篇关于聚焦或单击时如何突出显示 ImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:聚焦或单击时如何突出显示 ImageView?

基础教程推荐